如何获得带有嵌入式额外字段的联接数据?

时间:2019-02-19 08:24:52

标签: mongodb aggregate lookup

我有包含嵌入式资产文档的用户集合,其中一个id是userid,另一个是extra field。我要提取资产以及其他字段

 ---main table--------------
"assets" : {
    "tenant_profile_image" : [
        {
            "asset_id" : ObjectId("5c63d96e4473764be92eef22"), 
            "is_leading" : NumberInt(1)
        }

    ]
}
 ---- assets table -----

{ 
"_id" : ObjectId("5c63d96e4473764be92eef22"), 
"asset_url" : "image_url", 
"asset_type" : "image", 
"bucket_key" : "", 
"synced" : NumberInt(1), 
"created_at" : ISODate("2019-02-13T08:46:38.000+0000"), 
"updated_at" : ISODate("2019-02-13T08:46:38.000+0000")
 }
---expected result ----------
assets : [
        {
            "_id" : ObjectId("5c63d96e4473764be92eef22"), 
             "asset_url" : "image-url", 
             "asset_type" : "image", 
             "bucket_key" : "", 
              "synced" : NumberInt(1), 
              "created_at" : ISODate("2019-02-13T08:46:38.000+0000"), 
              "updated_at" : ISODate("2019-02-13T08:46:38.000+0000"),
              "is_leading":1
       }
     ]

0 个答案:

没有答案