Mongodb $lookup将集合合并到一个新的集合中



首先,我是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 
}
])

相关内容

最新更新