I've been hunting through the mongoengine documentation and around stack overflow and there doesn't seem to be a very clear answer to this so I'm asking: how do you best query a DictField? example code:
class Note(Document):
someData = DictField()
note = Note()
note.someData['someID'] = {"name": "Steve", "age":25}
note.save()
The closest I could find in the docs would be:
Note.objects(someData__name="Steve")
but that hasn't been working Again, feel like this should be a simple answer. Thanks for your help
You have wrong request, because you miss someID
.
See you structure in db:
>>> db.note.findOne()
>>> {
"_id": ObjectId("'0'*24")
"someData": {
"someID": {
{"name": "Steve", "age":25}
}
}
}
So right request will be Note.objects(someData__someID__name="Steve")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With