Skip to main content
edited tags
Link
Blakes Seven
  • 50.5k
  • 14
  • 132
  • 136
Source Link
hex20dec
  • 127
  • 2
  • 9

How do I create a query from an array with mongoose?

So I have this array with 3 IDs: ["56ba576f66b9add00e4d3082","56b9252266b9add00e4d3080","56b908f166b9add00e4d307f"]

I want to build a query that says something like that:

userModel.find({ $or: 
  [ 
    {_id:"56ba576f66b9add00e4d3082"}, 
    {_id:"56ba576f66b9add00e4d3082"}, 
    {_id:"56ba576f66b9add00e4d3082"} 
  ]}, 
    {email:true});

Is there some sort of a method to use in order to produce such query with the array? Should I be using mapReduce or the $where method or anything else? (I never used those before so I'm not sure if this is the case or not)

Perhaps I'm asking the wrong question? Any recommendations are very much welcome.