$match
我正在为我的聚合中的一个阶段寻找一个查询,它与这个问题几乎相同,但是..
结果应该是这样的:
[
{
"method": 3,
"item": 1,
"rank": 3 //because it has field named rank, and suits condition {rank: $max}
},
{
"method": 4,
"item": 1 //we need this, because document doesn't have rank field at all
},
{
"method": 5,
"item": 1 //we need this, because document doesn't have rank field at all
}
]
我已经尝试过的事情:
{
$match: {
$or: [
{item: id, rank: {$exists: true, $max: "$rank"}}, //id === 1
{item: id, rank: {$exists: false}} //id === 1
]
}
}
UPD:就目前而言,可能我不仅限于$match阶段,$project默认匹配后也相关,所以我可以在$match阶段请求每个文档,id无论是否有 docrank字段,然后在$project阶段做一个“按等级分离”$exists
喵喔喔
慕神8447489
相关分类