2014-02-28 27 views
0

我想從非空的屬性中獲取mongodb的文檔。如何從mongo獲取非空屬性文件

document1 
     { 
      "reviews" : { "title" : "Hello"} 
     } 

     document2 
     { 
      "reviews": {} 
     } 

預期文檔

document1 
     { 
      "reviews" : { "title" : "Hello"} 
     } 

回答

1

您使用$exists。簡單的用法。

db.collection.find({ "reviews.title": {$exists: true } }) 
0

你可以使用:

{ reviews: { $exists: true } } 

編輯:

還需要檢查 「空對象」:

{"reviews": {$exists:true, "$ne":{}}} 
+0

這實際上還是回到空白文檔。 –