【问题标题】:Will mongodb use 2 indexes in this $or query?mongodb 会在此 $or 查询中使用 2 个索引吗?
【发布时间】:2022-12-31 19:42:47
【问题描述】:

指标一:

{
  A: 1
}

指标二:

{
  B: 1
}

询问:

db.col.aggregate([
  {
    $match: {
      $or: [
        A: { $eq: 100 },
        B: { $eq: 100 },
      ]
    }
  }
])

mongodb 会在此查询中同时使用这两个索引吗?

【问题讨论】:

  • 你试过了吗?我们已经提到检查explain()输出我是你最近的一些问题。运行命令并查看考虑了哪些计划(rejectedPlans 字段)和选择了哪些计划(winningPlan)应该很快。 `$or 文档页面也有关于索引使用的详细信息

标签: mongodb mongodb-query aggregation-framework mongodb-indexes


【解决方案1】:

根据文档:

https://www.mongodb.com/docs/manual/reference/operator/query/or/

它将使用两个索引。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多