簡體   English   中英

詞典字典 - python Mongo Db

[英]Dictionary of dictionary - python Mongo Db

我想要找到價值 - 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"})

結果 - 無。

您必須使用點符號來獲得您要查找的內容。 是這樣的:

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

在此查詢中,您要查詢的是文檔,其中 18998750 是一個 object,看起來像{"title": "Reuters"} ,因此如果您知道整個子文檔,則此方法有效。

這里有幾個相關的問題:

使用 collection.find() 在 pymongo 中嵌套查詢

使用 find() 在 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM