beginner at nodejs and mongoose.
I have a schema like this
schema = new Schema({
username: String,
items: [Number]
});
Now, i want to make a call something like
var myItemsArray = [10,5,23,534];
user.find({items: myItemsArray}, function(err, user){});
Basically, i want the call to return the user if it has any of the above items.
Thanks
You need to make use of the $in
operator
user.find({items: {$in: myItemsArray}}, function(err, user){
console.log(err, user);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With