Hi,
I'm trying to query my document which has a DictField (data) containing a list of string in the field value, like this:
{
"_cls" : "Record.ReviewRecord",
"_id" : ObjectId("512da2e18db94274236596f0"),
"_types" : [
"Record",
"Record.ReviewRecord"
],
"application_id" : ObjectId("512d9f1221b8ab624284973f"),
"data" : {
"512d9d2121b8ab6242849727" : [
"512d9d2121b8ab624284972b"
],
"512d9d2121b8ab6242849732" : [
"512d9d2121b8ab6242849734"
]
},
}
In MongoDb I get 2 results as expected using this:
db.record.find({"wizard_id": ObjectId("512d9d2021b8ab6242849721"), "data.512d9d2121b8ab6242849727": '512d9d2121b8ab624284972b'})
In Python, I use this which I thought would produce the same query and thus result:
Record.objects.filter(wizard_id=ObjectId('512d9d2021b8ab6242849721'), data__512d9d2121b8ab6242849727=['512d9d2121b8ab624284972b'])
Instead I get empty array back.
My initial thought was that the way I construct the query keyword for the data dictfield isn't working so I use the __raw__:
Record.objects.filter(__raw__={'wizard_id': ObjectId('512d9d2021b8ab6242849721'), 'data.512d9d2121b8ab6242849727': '512d9d2121b8ab624284972b'})
This also returns empty array as result. So I decided to try the query as pymongo query:
collection = ApplicationRecord._get_collection()
collection.find({'wizard_id': ObjectId('512d9d2021b8ab6242849721'), 'data.512d9d2121b8ab6242849727': '512d9d2121b8ab624284972b'})
This times I get the 2 records back in the result!
So what's going on here? Am I not constructing the query correctly in python using mongoengine API? Is this a limitation of the lib at the moment?
Thanks