2015-08-26 108 views
1

我想弄清楚如何選擇符合Mongoose標準的數組中的某些對象。在數組中的Mongoose布爾查詢返回所有記錄

假設以下記錄:

var Record = { 
    records : [{name : "you can't look', isPublic : false}, 
       {name : "ok you can look', isPublic : true}, 
       {name : "you can look here too', isPublic : true}] 
} 

而下面的查詢:

Record.find({'records.isPublic' : true}, function (error, response) { 
    //This returns all the records, rather than just 0 and 2. 
}); 

任何想法,將不勝感激。

回答

0

使用db.collection.aggregate$unwind$match

0

嘗試類似的東西:

Record.find({}, {'records': {$elemMatch: {'isPublic': 'true'}}}), function (error, response) { 
    // finds everything, but projects only those which 'isPublic': 'true' 
}); 
相關問題