Keegan Riley Keegan Riley - 8 months ago 111
Javascript Question

Node js mongodb, mongoose find multiple items

So I wanna find multiple items so I don't have to loop sense I was told not to do that.

{ "_id" : ObjectId("59d2b1cf8cec1709f85eb7a9"), "title" : "Arrow", "common_movies" : [ ], "__v" : 0 }
{ "_id" : ObjectId("59d2b1cf8cec1709f85eb7aa"), "title" : "Gotham", "common_movies" : [ ], "__v" : 0 }

my database's movie collection looks like this.
and I want an array with 2 items in it, the Arrow and Gotham objects, This is what I tried

Movie.find({title: "Arrow"}, {title: "Gotham"}, function(err, foundMovie){

Answer Source

If you want to select movies where name is Arrow or Gotham, then you should use or operator in your criteria object: var criteria = { $or: [ {title: 'Arrow'}, {title: 'Gotham'} ]}. See mongodb documentation about OR logical operator.

Then use criteria object in your find method:

Movie.find(criteria, function(err, foundMovie){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download