5
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

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Is there a reason in your SQL example that you're using `LIKE` instead of `IN`? – JohnnyHK Nov 12 '16 at 14:07
  • 1
    Does this answer your question? [mongodb/mongoose findMany - find all documents with IDs listed in array](https://stackoverflow.com/questions/8303900/mongodb-mongoose-findmany-find-all-documents-with-ids-listed-in-array) – Mir-Ismaili Sep 14 '20 at 02:26

2 Answers2

3

Try using $or:

table.find( { $or:[ {'sport_type':'Cricket'}, {'sport_type':'Football'} ]}, 
  function(err,docs){
    // do something
});
Divyanshu Maithani
  • 13,908
  • 2
  • 36
  • 47
  • the equivalent of your answer is `Select * from table_name where sport_type = 'Cricket' or sport_type = 'Football';`. He looks for a `LIKE` comparison. – hzitoun Nov 12 '16 at 14:12
  • @Mitchapp the OP is trying to find documents with `sport_type` of `Cricket` or `Football`. I don't think he is looking for a pattern. – Divyanshu Maithani Nov 12 '16 at 14:15
3

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.