0
我们有三个集合代表一个类别。当用户想要查看某个类别中最近发生的事务时,我们需要从这些集合中获取并显示。我在stackoverflow中看到一些提及聚合多个集合的问题是不允许的。那么,有没有其他的选择。由于提前聚合多个蒙戈集合和替代
我们有三个集合代表一个类别。当用户想要查看某个类别中最近发生的事务时,我们需要从这些集合中获取并显示。我在stackoverflow中看到一些提及聚合多个集合的问题是不允许的。那么,有没有其他的选择。由于提前聚合多个蒙戈集合和替代
如果你是与成千上万的来自收集的记录工作,你可以更好的使用MongoDB中“查找”的方法去。对于数十亿条记录来说是不可取的。
链接:https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/
前,
db.table1.aggregate([
// Join with user_info table
{
$lookup:{
from: "table2", // other table name
localField: "userId", // name of table1 field
foreignField: "userId", // name of table2 field
as: "t1" // alias for table1
}
},
// Join with user_role table
{
$lookup:{
from: "table3",
localField: "userId",
foreignField: "userId",
as: "alias name"
}
}
]);