【发布时间】:2017-10-17 03:51:58
【问题描述】:
我想查找该字符串是否存在于架构中 food 内的 shop_name 或 name 中。
这里是查询
dbModel.stores.find({ "food.name": { '$regex': re } }).or([{ 'shop_name': { '$regex': re } }]).exec(function(err, docs) {
if (!err) {
res.status(200).json({
"success": "1",
"message": docs
});
} else {
res.status(200).json({
"success": "0",
"message": "No result found"
});
}
});
这是我的架构
var storeSchema = {
"area": String,
"food": [{
'name': String,
'description': String
}],
"shop_name": String
};
我想显示与shop_name 或food.name 中的字符串匹配的记录
只有当字符串包含在两个元素中时,上面才会给我记录。我如何使用or 进行检查,即如果 shop_name 或 food.name 匹配,那么它应该显示它
【问题讨论】:
标签: arrays node.js mongodb mongoose schema