- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
考虑以下文档:
A 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"
]
}
A users
文档
{
"_id" : "7b0dcd22-c3bb-426f-8235-671b82acee98",
"userInfo" : {
"avatarKey" : "7b0dcd22-c3bb-426f-8235-671b82acee98/avatars/Dandelion.png",
"familyName" : "Doe",
"givenName" : "John"
}
}
在 mongo shell 中,我尝试检索 communications
与 messages.authorId
“填充”为 userInfo
我的领域user
文档。
我尝试用 $lookup
来做到这一点像这样:
db.communications.aggregate([
{
$lookup:
{
from: "users",
localField: "messages.authorId",
foreignField: "_id",
as: "messages.authorId"
}
}
])
但是场messages.authorId
被覆盖。
我如何“填充”我的 userInfo
字段而不替换现有值?
感谢您的帮助。
最佳答案
因为你的messages
是一个数组字段,当您提供 .dot
时,它会用新对象覆盖现有数组。 as
中的符号 ( "messages.authorId"
) 表达式。
因此,如果您想填充 messages
内的每个用户您需要 $unwind
的数组messages
首先添加一个新的数组,然后 $group
再次回滚到数组中。
db.communications.aggregate([
{ "$unwind": "$messages" },
{ "$lookup": {
"from": "users",
"localField": "messages.authorId",
"foreignField": "_id",
"as": "messages.authorId"
}},
{ "$unwind": "$messages.authorId" },
{ "$group": {
"_id": "$_id",
"messages": { "$push": "$messages" },
"type": { "$first": "$type" },
"title": { "$first": "$title" },
"receivers": { "$first": "$receivers" }
}}
])
关于mongodb - "populate"具有 $lookup 的字段而不覆盖现有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53618475/
如果查找返回 null 该怎么办?我正在使用 org.openide.util.Lookup 的 Lookup.getDefault().lookup() ,它用于查找对象的实例。一般模式是传递一个
我尝试了两种方法来获取给定函数的 MethodHandle。 Method 1 Method m = MyClass.class.getMethod("myMethod", String.class,
前言 前面几节都是讲的基础内容,本节我们讲讲索引性能优化,当对大数据进行处理时首先想到的就是索引,一旦遇到这样的问题则手忙脚乱,各种查资料,为何平常不扎实基本功呢,我们由浅入深,简短的内容,深入的
我试图理解 System.Linq.Lookup类(class)。调用GetType()时,显示如下: System.Linq.Lookup`2+Grouping[System.Object,Syst
什么是依赖于参数的查找有哪些好的解释?许多人也称其为Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么不好? 如何运作? 最佳答案 Koenig查找或 Argument Dep
关于什么是参数相关查找有什么好的解释?许多人也称它为 Koenig Lookup。 最好我想知道: 为什么是好事? 为什么是坏事? 它是如何工作的? 最佳答案 Koenig 查找 , 或 Argume
我有两个 mongo 集合,一个包含约会提醒,另一个包含通知。我正在尝试返回给定的branchId/clinic_id中的所有存档:错误提醒的结果,并包括其已确认的:错误通知。另外,我想确保约会显示在
关于什么是参数依赖查找有什么好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何工作的? 最佳答案 Koenig 查询 , 或
我正在 AX 2009 中的一个表单上创建一个项目。有一个名为“SubsPersonName”的查找字段,它使用以下方法对 ContactPerson 表执行查找。 public void looku
关于什么是参数依赖查找有哪些好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何工作的? 最佳答案 Koenig 查找,或 A
关于什么是参数依赖查找有哪些好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何运作的? 最佳答案 Koenig 查找,或 A
关于什么是参数依赖查找有哪些好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何工作的? 最佳答案 Koenig 查找,或 A
关于什么是参数依赖查找有哪些好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何工作的? 最佳答案 Koenig 查找,或 A
关于什么是参数依赖查找有哪些好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何运作的? 最佳答案 Koenig 查找,或 A
关于什么是参数依赖查找有哪些好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何运作的? 最佳答案 Koenig 查找,或 A
关于什么是参数依赖查找有哪些好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何工作的? 最佳答案 Koenig 查找,或 A
关于什么是参数依赖查找有哪些好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何工作的? 最佳答案 Koenig 查找,或 A
关于什么是参数依赖查找有什么好的解释?许多人也将其称为 Koenig Lookup。 最好我想知道: 为什么这是一件好事? 为什么这是一件坏事? 它是如何工作的? 最佳答案 Koenig 查找,或 A
以下函数将电话号码作为输入参数(例如 +436641234567 或 +436641234567)并在联系人数据库中执行两次查找:首先,识别属于该号码的用户(这已经有效),然后使用该 ID用户的 获取
我设置了一个运行centos6.2 64位的virtualbox客户端机器,主机是windows7 64位,并在客户端机器上设置了两个网卡,一个是NAT模式,一个是host-only模式,然后我就陷入
我是一名优秀的程序员,十分优秀!