i have feeling may have been asked elsewhere, having tough time finding answer.
basically, have mongodb/mongoose schema stores list of registered users. building gui can query records meet conditions. in case, wanting let gui users select via checkboxes genders they'd include in query.
if passing in string, know i'd write follows:
user.find({"gender": gender}).exec(function(err, users){ if(err) res.send(err); res.json(users); });
but since i'll possibly passing in array of options, there native mongoose function can use query following cases?
[male] [male, female, other] [male, other] [female] etc.
what best way write query in mongoose?
thanks!
you should use $in
operator
var gender = [male, female, other] user.find({"gender": {$in: gender}})
Comments
Post a Comment