简体   繁体   English

词典字典 - python Mongo Db

[英]Dictionary of dictionary - python Mongo Db

I want find value - db.mycol.find({"title":"Reuters"})我想要找到价值 - db.mycol.find({"title":"Reuters"})

{'_id': ObjectId('63b8dfbfd651efc35007b66c'), '18998750': {'pageid': 18998750, 'ns': 0, 'title': 'Reuters', 'extract': 'Reuters ( (listen), ROY-terz) is a news agency owned by Thoms
db = clu["Collections"]

col = db["wik"]

col.find({"title":"Reuters"})

Results - None.结果 - 无。

You have to use dot notation to get what you're looking for.您必须使用点符号来获得您要查找的内容。 Something like this:是这样的:

col.find({"18998750.title":"Reuters"})

In this query, what you're asking for is documents where 18998750 is an object that looks like {"title": "Reuters"} , so this works if you know the entire subdocument.在此查询中,您要查询的是文档,其中 18998750 是一个 object,看起来像{"title": "Reuters"} ,因此如果您知道整个子文档,则此方法有效。

Here are a couple of related questions:这里有几个相关的问题:

nested queries in pymongo using collection.find() 使用 collection.find() 在 pymongo 中嵌套查询

Using find() to search for nested keys in MongoDB 使用 find() 在 MongoDB 中搜索嵌套键

And some references:和一些参考资料:

https://www.tutorialspoint.com/using-find-to-search-for-nested-keys-in-mongodb https://www.tutorialspoint.com/using-find-to-search-for-nested-keys-in-mongodb

https://www.mongodb.com/community/forums/t/query-nested-documents-mongodb-with-python-pymongo/101554/4 https://www.mongodb.com/community/forums/t/query-nested-documents-mongodb-with-python-pymongo/101554/4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM