ffxsam
ffxsam

Reputation: 27763

MongoDB - Is there a boolean AND version of $in?

This operation finds all uploads that have tags "important" OR "school":

db.uploads.find({tags: {$in: ['important', 'school']}})

What I want do is show only uploads that have tags "important" AND "school." Is this the only way?

db.uploads.find({$and: [{tags: 'important'}, {tags: 'school'}]})

Upvotes: 1

Views: 45

Answers (1)

Rohit Jain
Rohit Jain

Reputation: 2092

You need to use $all operator:

db.uploads.find( { tags: { $all: [ "important", "school"] } } )

Upvotes: 2

Related Questions