Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-15990

Unclear when an aggregation pipeline can use indexes

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Cannot Reproduce
    • Icon: Minor - P4 Minor - P4
    • Server_Docs_20231106
    • None
    • manual, Server
    • None
    • 2

    Description

      https://www.mongodb.com/docs/manual/core/aggregation-pipeline-optimization/#indexes

      In this section, I was expecting to find the list of stages that completely prevent the use of indexes further down the pipeline. 

      For example I was convinced that $project and $unset were preventing any indexes from being used based on the documentation but I was surprised to see that these 2 pipelines can actually both use an index on {name:1}.

      db.c.explain(true).aggregate([{"$project": {"age":0}},{"$match": {name:"Max"}}])
      db.c.explain(true).aggregate([{"$unset": "age"},{"$match": {name:"Max"}}])

       

      Can we improve the doc to be more precise?
      Thanks!

      Attachments

        Activity

          People

            lauren.tran@mongodb.com Lauren Tran
            maxime.beugnet@mongodb.com Maxime Beugnet
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              13 weeks, 6 days ago