我试图通过使用mongoose过滤器从我的mongoDB数据库中获取数据.这种情况下,数据库中的每个用户对象都有某些字段,比如"Region"或"Sector".
目前,我正在获取所有包含关键字"region"的用户,如下所示:
// Filter all healthcare bios by region
app.get('/user',function(req, res) {
// use mongoose to get all users in the database
User.find({region: "NA"}, function(err, user)
{
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
if (err)
{
res.send(err);
}
// return all todos in JSON format
console.log(user);
res.json(user);
});
});
How can put some conditions in mongoose that it return users that contain both "region" && "Sector" in their objects.目前它只返回包含region关键字的用户.
我试过使用$和operator,但无法使其工作.