Best way to request DictField in MongoEngine

I hunted through the mongoengine documentation and around, and there seems to be no very clear answer to this question, so I ask: what is the best way you request DictField? code example:

class Note(Document): someData = DictField() note = Note() note.someData['someID'] = {"name": "Steve", "age":25} note.save() 

The closest I could find in the docs:

 Note.objects(someData__name="Steve") 

but it doesn’t work. Again, I feel that this should be a simple answer. Thank you for your help.

+6
source share
1 answer

Your request is incorrect because you are missing someID .

See the structure in db:

 >>> db.note.findOne() >>> { "_id": ObjectId("'0'*24") "someData": { "someID": { {"name": "Steve", "age":25} } } } 

So the correct request would be Note.objects(someData__someID__name="Steve") .

+9
source

Source: https://habr.com/ru/post/951845/


All Articles