我的模型看起来是这样的:
Collection = new Schema({
name: {type: String, required: true},
tags: [String],
movies: [{_id: false,
original_title: {type: String}}]
)};我需要修改以下查询,以使用“req.body”(字符串数组),不仅在“标记”数组中查找匹配项,而且在电影数组中找到与“original_title”字段匹配的匹配项(Es)。
Collection.find({'tags' : { $in : req.body}}, (err, collections) => {
if(err){res.status(400).json(err);}
if(!collections)
{
res.status(404).json({message: 'No collections found'});
}else{
res.json(collections);
}
}).limit(8);发布于 2017-04-12 17:40:02
试试这个:
db.collection.find({
$or: [{
'tags': {
$in: req.body
}
},
{
'original_title': {
$in: req.body
}
}
]
}, (err, collections) => {
if (err) {
res.status(400).json(err);
}
if (!collections) {
res.status(404).json({
message: 'No collections found'
});
} else {
res.json(collections);
}
}).limit(8);https://stackoverflow.com/questions/43376004
复制相似问题