在从NodeJS查询Mongo时,如何在同一个JSON字段上实现逻辑OR?
特别是,我有以下几行:
collection.find({"user":req.user.email, "parent._id":0}, function(err, activities){
if (err) throw err;
res.json(activities);
});
我怎样才能正确地包含“父”:{}这样的条目?
以下给我一个空数组:
collection.find({"user":req.user.email, "parent":{}, "parent._id":0}, function(err, activities){
if (err) throw err;
res.json(activities);
});
答案 0 :(得分:0)
工作代码:
collection.find({"user":req.user.email, $or:[{"parent._id":0},{"parent":{}}]}, function(err, activities){
if (err) throw err;
res.json(activities);
});