Waterline, find array in array

我只是一个虾纸丫 提交于 2019-12-13 13:07:52

问题


I have Video model:

module.exports = {

  attributes: {
    id: 'string',
    tags: 'array'
  },
}

I want to find all videos with tags for example "Hello" or "World". I could easy get all videos like: Video.find({tags:"Hello"}). I saw examples where searching id: [1,2,3] but not when key(id => tags) is array.


回答1:


Use the "in"-Statement in combination with "contains"

Video.find({tags: { contains: ["some1","some2"]}}).exec(function(err,res){
    console.log(res);
});

See: https://github.com/balderdashy/waterline-docs/blob/master/queries/query-language.md




回答2:


try this:

Video.find({tags: {"$in" : ["sometag1", "sometag2"]}})



回答3:


Maybe this..

var filtered = module.exports.filter(function () {
    return this.tags.indexOf("string") != -1
});


来源:https://stackoverflow.com/questions/24166253/waterline-find-array-in-array

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