【问题标题】:Complex join on mongodb collection and filter on large tablesmongodb 集合上的复杂连接和大型表上的过滤器
【发布时间】:2018-08-14 10:26:11
【问题描述】:

这与使用 $lookup 加入多个集合和使用 $match 过滤有关

我们有具有以下属性的订单产品集合:

orderProduct(基础集合)

_id
productId
qty
retailerId
supplierId
unitPrice
lineTotal

产品(依赖集合)

_id
productName
subCategoryId

零售商(依赖集合)

_id
retailerName

供应商(依赖集合)

_id
supplierName

现在我们需要从依赖集合和基础集合中进行以下连接和选择属性

orderProduct joins Product
orderProduct joins Retailer
orderProduct joins Supplier

还需要从依赖集合和基础集合中过滤。 上述设置的基本问题是orderProduct 正在快速增长(当前大小为 90K)而$lookup 花费了太多时间。这里也需要排序/限制/跳过。

当我们应用查找时,它工作正常,但当我们应用匹配时,它会在每次引入过滤器时减慢。

有什么优雅的方法来处理这个问题吗?

提前致谢

【问题讨论】:

标签: mongodb lookup


【解决方案1】:

如果您想加入某事,MongoDB 不是一个有效的选择。我会在一个系列上进行操作。因此,每个文档都需要具有执行查询的所有信息。或许,您可以在 orderProduct 文档中添加两个字段:

{
  orderProductId: 1,
  product: {name: "product", id: 1}
  retailer: [{id: 1, name: "Company"}],
  supplier: [{id: 1, name: "Company"}]
}

【讨论】:

    猜你喜欢
    • 2021-06-25
    • 2014-04-09
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    相关资源
    最近更新 更多