如何进行查询以连接另一个集合和一个子集合
MongoDB 4.0
用作聚合函数的功能,请查阅,但找不到将这两个集合连接在一起的功能
收藏夹联系人
{
"_id" : ObjectId("5cce58d1c05a0d1247ae9f06"),
"name" : "harry",
"management" : [
{
"_id" : ObjectId("5cce58d1c05a0d1247ae9f0b"),
"management" : "m1",
"user" : ObjectId("5cce4e316cf7f20e6f27cef2")
}
]
}
收藏用户
{
"_id" : ObjectId("5cce4e316cf7f20e6f27cef2"),
"firstName" : "jeff",
"lastName" : "ag",
"email" : "user@test.com",
}
需要结果
{
"_id" : ObjectId("5cce58d1c05a0d1247ae9f06"),
"name" : "harry",
"management" : [
{
"_id" : ObjectId("5cce58d1c05a0d1247ae9f0b"),
"management" : "m1",
"user" : {
"_id" : ObjectId("5cce4e316cf7f20e6f27cef2"),
"firstName" : "jeff",
"lastName" : "ag",
"email" : "user@test.com",
}
}
]
}