我在MongoDB中有这样的文档:
{"ONE": {"TWO": {"THREE":"5"}}}
我想使用 Pymongo find
API 查询 mongoDb,但它不起作用:
for value in dbaccess.find({"ONE":{"TWO":{"THREE":{"$gt":"0"}}}}):
print value
上面的代码没有打印任何东西。
两件事:
- 如果要将文档中的 5 视为整数,请不要将其括在双引号中。
-
使用点表示法查询嵌套文档:
dbaccess.find("ONE.TWO.THREE": {"$gt": 0})