0

Say I have a collection book, like this:

{
   name:"xxxx",
   tags:["thriller", "novel", "modern"]
}

How can I query all the books that have at least one of the tags: "novel","music" ? Is there a way like :

db.inventory.find( { tags: { $containsAny: ["novel","music"] } } )

Thanks in advance.

matrix
  • 349
  • 3
  • 12
  • The other answer in the marked dupe solves your problem with the `$in` operator as `db.inventory.find( { tags: { $in: ["novel", "music"] } } )` – chridam Apr 24 '17 at 08:07

1 Answers1

-1

You can use $in operator. You can query to get all the books that have at least one of the tags. query like

db.inventory.find({tags: {$in:['novel', 'music']}})
Shaishab Roy
  • 16,335
  • 7
  • 50
  • 68