MongoDB加入3集合

MongoDB加入3集合,mongodb,join,lookup,Mongodb,Join,Lookup,我现在创建3个集合。(用户、业务、业务信息) 我想加入一切 users.user\u id->business.user\u id| business.business\u id->business\u info.business\u id 如果你能在这件事上帮忙,我很高兴 多谢各位 您可以使用lookup在Mongo中加入两个集合 db.firstCollection.aggregate({ $lookup:{ from:"seconedCollection",

我现在创建3个集合。(用户、业务、业务信息) 我想加入一切

users.user\u id->business.user\u id| business.business\u id->business\u info.business\u id

如果你能在这件事上帮忙,我很高兴


多谢各位

您可以使用lookup在Mongo中加入两个集合

db.firstCollection.aggregate({
    $lookup:{
        from:"seconedCollection",
        localField:"commonKey", 
        foreignField:"commonKey",
        as:"firstCollection_seconedCollection"
    } 
})

你能举个例子吗?你应该看看谢谢你我可以用这个方法连接两个集合。但是我如何将第三个收藏与第二个收藏联系起来呢?是的,这是可能的。使用SQL建模模式和滥用聚合工具使MongoDB适应这种错误的方式是一个好主意吗?没有那么多。