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){
console.log(foundMovie)
});
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){
console.log(foundMovie)
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.