Irs*_*haq 1 mongoose mongodb nosql mongodb-query
我有两个收藏user和transaction. 我想要获取user不在exists集合中的记录transaction。然后我就这样做
[
{
"$lookup" : {
"from" : "transaction",
"localField":"_id",
"foreignField":"user",
"as" : "trans"
}
},
{
"$match": { "transaction.user": { "$exists": false } }
},
{"$limit":20}
]
Run Code Online (Sandbox Code Playgroud)
但我没有记录我想要的东西。
小智 13
聚合自user至transaction集合。正如 @thammada.ts 所提到的,你应该trans像$match这样使用
db.user.aggregate([
{
"$lookup": {
"from": "transaction",
"localField": "_id",
"foreignField": "user",
"as": "trans"
}
},
{
"$match": {
"trans.user": {
"$exists": false
}
}
}
])
Run Code Online (Sandbox Code Playgroud)
_id还要验证集合中user和集合user
中两个字段的类型transaction。
| 归档时间: |
|
| 查看次数: |
8680 次 |
| 最近记录: |