【发布时间】:2015-01-16 05:18:43
【问题描述】:
我正在 mongodb 中搜索从 A 到 B 的所有消息以及从 B 到 A 的所有语句。这样我可以进行对话
从:A 人 AND 到:B 人
或
从:B 人 AND 到 A 人
// Create a conversation
db.collection('messages', function (err, collection) {
collection.find(
{ // how do I turn this $and into a two nested $and statements inside $or?
$and: [{
receiver: new BSON.ObjectID(req.user._id)
}, {
sender: new BSON.ObjectID(req.body.sender)
}]
}
).sort({
date: -1
}).toArray(function (err, docs) {
console.log(docs);
})
});
【问题讨论】:
-
类似于$and,只需使用整个$and查询作为$or的一个参数
-
感谢处理器!我是否将整个 $and 括在大括号中?
标签: mongodb