首先,我是 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/