Note that there are some explanatory texts on larger screens.

plurals
  1. POusing key as value in Mongoengine
    primarykey
    data
    text
    <p>I use mongoengine for mongodb in django.</p> <p>but.. mongoengine fields (like StringField) makes me build up schema toward the way that I don't want. I mean, it strictly insists that I pre-write key name before I do know what it will be. for example...</p> <p>in case that I do not know what key name will be put into database...</p> <pre><code>&gt; for(var i=0; i&lt;10; i++){ ... o = {}; ... o[i.toString()] = i + 100; ... db.test.save(o) ... } &gt; db.test.find() { "_id" : ObjectId("4ed623aa45c8729573313811"), "0" : 100 } { "_id" : ObjectId("4ed623aa45c8729573313812"), "1" : 101 } { "_id" : ObjectId("4ed623aa45c8729573313813"), "2" : 102 } { "_id" : ObjectId("4ed623aa45c8729573313814"), "3" : 103 } { "_id" : ObjectId("4ed623aa45c8729573313815"), "4" : 104 } { "_id" : ObjectId("4ed623aa45c8729573313816"), "5" : 105 } { "_id" : ObjectId("4ed623aa45c8729573313817"), "6" : 106 } { "_id" : ObjectId("4ed623aa45c8729573313818"), "7" : 107 } { "_id" : ObjectId("4ed623aa45c8729573313819"), "8" : 108 } { "_id" : ObjectId("4ed623aa45c872957331381a"), "9" : 109 } </code></pre> <p>[addition]</p> <p>as you can see above, key is very different from each other.. just assume that "I do not know what key name will be put into document as key ahead of time</p> <p>as dcrosta replied.. I am looking for a way to use mongoengine without specifying the fields ahead of time.</p> <p>[/addition]</p> <p>How can I do the same thing through mongoengine? please give me schema design like</p> <pre><code>class Test(Document): tag = StringField(db_field='xxxx') </code></pre> <p>[addition]</p> <p>I don't know what 'xxxx' will be as key name.</p> <p>sorry.. I'm Korean so my english is awkward. please give me your some knowledge. Thanks for reading this.</p> <p>[/addition]</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload