Sails-mongo. Find in array

Deadly 提交于 2019-12-13 12:49:33

问题


I'm using sails.js and sails-mongo adapter. Suppose I have a model:

module.exports = {

  attributes: {

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

            ,   tags: {
                    type: 'ARRAY'
            }
    }

  }

};

How can I carry out a search in an tags array?


回答1:


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



回答2:


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

there are a great example here: http://docs.mongodb.org/manual/reference/operator/projection/elemMatch/

with waterline

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


来源:https://stackoverflow.com/questions/19110553/sails-mongo-find-in-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!