Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waterline, find array in array

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.

like image 720
vromanch Avatar asked Jun 11 '14 14:06

vromanch


2 Answers

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

like image 119
mdunisch Avatar answered Nov 03 '22 15:11

mdunisch


try this:

Video.find({tags: {"$in" : ["sometag1", "sometag2"]}})
like image 24
vromanch Avatar answered Nov 03 '22 15:11

vromanch