6

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.

kojiro
  • 74,557
  • 19
  • 143
  • 201
vromanch
  • 939
  • 10
  • 22

3 Answers3

2

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

adriaan
  • 1,088
  • 1
  • 12
  • 29
mdunisch
  • 3,627
  • 5
  • 25
  • 41
1

try this:

Video.find({tags: {"$in" : ["sometag1", "sometag2"]}})
vromanch
  • 939
  • 10
  • 22
-2

Maybe this..

var filtered = module.exports.filter(function () {
    return this.tags.indexOf("string") != -1
});
kidwon
  • 4,448
  • 5
  • 28
  • 45
Erik Simonic
  • 457
  • 3
  • 13