Mongoose find with multiple values for a field

Select * from table_name where sport_type LIKE ('Cricket','Football');

I am trying to find the documents with sport_typeof Cricket and Football using find

table.find({ sport_type : "Cricket" })

Can anyone help me to do so

Upvotes: 5

Views: 7389

Answers (2)

Rodolfo Dassaev
Rodolfo Dassaev

Reputation: 71

Maybe it's too late to answer but hopefully it will help other people.

You can use $in operator, like this:

mongoose.find({sport_type: {$in: ['Cricket', 'Football']}})

You provide an array to $in operator and it will return all the documents which have an exact sport_type in the array specified.

Upvotes: 3

Divyanshu Maithani
Divyanshu Maithani

Reputation: 14986

Try using $or:

table.find( { $or:[ {'sport_type':'Cricket'}, {'sport_type':'Football'} ]}, 
  function(err,docs){
    // do something
});

Upvotes: 3

Related Questions