如何使用MongoDB聚合匹配集合A上存在但集合B上不存在的文档?
收藏A:
[{
"_id": 1,
"operation":"SEC",
"name":"x"
},{
"_id": 2,
"operation": "SEC",
"name": "y"
},
{
"_id": 3,
"operation": "SEC",
"name": "z"
}]
收藏集B:
[
{
"_id": 1,
"operation": "SEC",
"name": "x"
},
{
"_id": 2,
"operation": "SEC",
"name": "y"
}
]
预期产出:
[
{
"_id": 3,
"operation": "SEC",
"name": "z"
}
]
1条答案
按热度按时间jdzmm42g1#
一种选择是使用具有
$$ROOT
和$match
不匹配文档的$lookup
管道:了解它在playground example上的工作原理