查询聚合子集合时出错

时间:2019-05-05 22:51:23

标签: mongodb

如何进行查询以连接另一个集合和一个子集合

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",
            }
        }
    ]
}

0 个答案:

没有答案