![](/img/trans.png)
[英]MongoDB query all documents contains ids that does not exist anymore in the collection
[英]How to query MongoDB for matching documents where item is in document array
如果我存儲的文檔如下所示:
doc = {
'Things' : [ 'one' , 'two' , 'three' ]
}
我怎樣才能查詢該文件包含one
在Things
?
我知道$in
運算符根據列表查詢文檔項,但這是相反的。 任何幫助都是極好的。
使用MongoDB的多鍵支持:
MongoDB提供了一個有趣的“多鍵”功能,可以自動索引對象值的數組。
[...]db.articles.find( { tags: 'april' } ) {"name" : "Warm Weather" , "author" : "Steve" , "tags" : ["weather","hot","record","april"] , "_id" : "497ce4051ca9ca6d3efca323"}
基本上,你不必擔心Things
的陣列,MongoDB會為你照顧; MongoDB shell中的這樣的東西可以工作:
db.your_collection.find({ Things: 'one' })
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.