Pymongo Query with Dictionary inside Dictionary?

mongodb, pymongo, python

Solution

Two things:

- If you want to treat the 5 in your document as an integer, don't enclose it in double quotes.

Use dot notation for querying nested documents:

`dbaccess.find("ONE.TWO.THREE": {"$gt": 0})`

Problem

I have Document in MongoDB like this: ``` {"ONE": {"TWO": {"THREE":"5"}}} ``` I want to query mongoDb using the Pymongo `find` API, but it's not working: ``` for value in dbaccess.find({"ONE":{"TWO":{"THREE":{"$gt":"0"}}}}): print value ``` Nothing is getting printed with the above code.

Original source