2013-10-01 48 views
0

我正在使用sails.js和sails-mongo適配器。假設我有一個模型:帆 - 蒙戈。在數組中查找

module.exports = { 

    attributes: { 

     shema: true 
    , attributes: { 
       description: { 
        type: 'TEXT' 
       , max: 200 
      } 

      , tags: { 
        type: 'ARRAY' 
      } 
    } 

    } 

}; 

如何在標籤數組中執行搜索?

回答

0
Model.find({ 
    'tags.title': { 
     contains: 'query' 
     } 
}) 
.done(function (err, response) { 
    /**/ 
}); 
+1

看代碼,它運行蒙戈的正則表達式$是昂貴的。看起來,對mongo的實際數組操作的支持不存在 – mobetta

-1
db.schools.find({ criteria }, 
      { atributes: { $elemMatch: { tags: value } } }) 

有一個很好的例子在這裏:http://docs.mongodb.org/manual/reference/operator/projection/elemMatch/

與水線

Model.native(function(err, collection) { 
    // Execute any query that works with the mongo js driver 
    collection.find({ criteria }, 
       { atributes: { $elemMatch: { tags: value } } }) 
    }); 
+1

您的答案顯示瞭如何通過mongo cli執行此搜索。問題是如何通過waterline.js實現搜索 –