0

I have user schema

{
phone:'String'
}

My query field is phone and i have an array of phone numbers like this ['1233','2134','43433'] to query;

I had to query user collection that this phone numbers are present or not in collection...

I wanted to complete this operation in single query rather then using async.each or some asynchronous operation.

Is it possible with single operation?

santhosh
  • 1,919
  • 3
  • 21
  • 33
  • 1
    Possible duplicate of [How to check if an array field contains a unique value or another array in MongoDB?](http://stackoverflow.com/questions/5366687/how-to-check-if-an-array-field-contains-a-unique-value-or-another-array-in-mongo) – Thomas Dec 28 '16 at 05:47
  • take a look at $in operator, https://docs.mongodb.com/manual/reference/operator/query/in/ – felix Dec 28 '16 at 05:48
  • guys phone is not an array @Thomas – santhosh Dec 28 '16 at 05:55

1 Answers1

0

You should use $in operator to find by phone

User.find({ phone : { $in : ['1233','2134','43433'] }}, function(err, users) {
  if(err) {
     //return error
  }
  console.log(users);
  //return success
});
Shaishab Roy
  • 16,335
  • 7
  • 50
  • 68