2012-03-19 50 views
14

是否可以在Mongo查詢中使用類似'exists'的內容來根據ID返回此記錄?Mongo:按關鍵字查詢一級深

類似於請選擇其中'ids'包含密鑰'123456'

{ 
     "department": "Digging", 
     "ids": { 
     "123456": { 
      "color": "blue" 
     }, 
     "123457": { 
      "color": "red" 
     } 
     } 
    } 

回答

16

當你與一個給定的名字尋找一個場的存在,$存在是你需要(見Advanced Queries)操作。

例如例如:

db.YourCollection.find({ "ids.123456" : {$exists: true}}); 
+0

完美!我真正需要的是點符號'db.YourCollection.find({「ids.123456」:{$ exists:true}});' – axiomx11 2012-03-19 19:06:53