gpt4 book ai didi

Mongodb $lookup 将集合合并成一个新集合

转载 作者:可可西里 更新时间:2023-11-01 10:42:00 24 4
gpt4 key购买 nike

首先,我是 mongodb 的新手,所以我的问题可能很愚蠢。

我有两个集合,我使用 $lookup

合并了它们
db.information.aggregate([     
{
$lookup: {
from: "extra_info",
localField: "identification",
foreignField: "identification",
as: "extra_info"
}
}
])

作为输出,我得到了我想要的“集合”,但它没有存储在db.information 集合。

有什么提示可以实现吗?

最佳答案

使用$out在聚合管道中将聚合数据保存到新集合中:

db.information.aggregate([     
{
$lookup: {
from: "extra_info",
localField: "identification",
foreignField: "identification",
as: "extra_info"
}
},
{
$out : "newcollection" // name of the collection to save the lookup in
}
])

关于Mongodb $lookup 将集合合并成一个新集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39328811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com