用$ lookup比较两个字段的查询

时间:2017-05-03 14:11:13

标签: node.js mongodb mongodb-query aggregation-framework

用户集合

[   
    {name: "alex", age: 25, surname: "brown"},
    {name: "tom", age: 34, surname: "gray"},
    {name: "alex", age: 65, surname: "red"},
    {name: "alex", age: 32, surname: "yellow"}
]

参与集合

[   
    {name: "alex", age: 32}
]

我想只获取一个文档的详细信息,其名称为alex,且年龄为32

到目前为止我做了什么?

db.participation.aggregate([
   {$lookup: "users" , foreignField: "name" , localField: "name", as: "document"},
   {$unwind: "document"},
   {$match: {age: "$document.age"}}
])

但是这没有返回任何内容,返回的数组为空。

那么我应该如何创建查询呢?

0 个答案:

没有答案