Node.js 查找ObjectId';带和';s和或';
我们正在应用程序中实现搜索。我们必须显示用户跟随的所有公共项或所有私有项。模式如下所示Node.js 查找ObjectId';带和';s和或';,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我们正在应用程序中实现搜索。我们必须显示用户跟随的所有公共项或所有私有项。模式如下所示 var ItemSchema = new Schema({ . . . followers: { type: Array } } 追随者被用户的objectid填满。 我试着用这个来找到它: Item.find() .and([ { name: new RegExp(searchText, 'i') }, { $or:
var ItemSchema = new Schema({
.
.
.
followers: {
type: Array
}
}
追随者被用户的objectid填满。我试着用这个来找到它:
Item.find()
.and([
{ name: new RegExp(searchText, 'i') },
{
$or: [
{ private: false },
{
$and: [
{ private: true },
{ followers: user._id }
]
}
]
}
])
.exec(function(err, item) {
if(err) {
console.log(err);
}
done(null, user, Item);
}
您可以将helper与一起使用
Item.find()
.or([
{ "private": true },
{ $and: [{ private: true },{ followers: user._id }
]}
])
.exec(function(err, item) {
...
}