请考虑以下文件:
communications
文档
{
"_id" : ObjectId("5c069a6acbd69e0f61983850"),
"type" : "request",
"title" : "test 1",
"messages" : [
{
"authorId" : "7b0dcd22-c3bb-426f-8235-671b82acee98",
"body" : "test 1",
"createdAt" : ISODate("2018-12-04T15:16:58.342Z")
}
],
"receivers" : [
"e75f3849-09bb-46a4-a05d-885b6d31ccc3"
]
}
users
文档
{
"_id" : "7b0dcd22-c3bb-426f-8235-671b82acee98",
"userInfo" : {
"avatarKey" : "7b0dcd22-c3bb-426f-8235-671b82acee98/avatars/Dandelion.png",
"familyName" : "Doe",
"givenName" : "John"
}
}
在 mongo shell 中,我尝试使用communications
的{{1}}字段中的messages.authorId
“填充”来检索userInfo
文档。
我试图用user
来做到这一点:
$lookup
但是字段db.communications.aggregate([
{
$lookup:
{
from: "users",
localField: "messages.authorId",
foreignField: "_id",
as: "messages.authorId"
}
}
])
被覆盖。
如何在不替换现有值的情况下“填充”我的messages.authorId
字段?
感谢您的帮助。