M036 - Index usage when renaming a field using a $project / $addField


So this is where prior to 3.6 if you used a project of a field and you renamed it, where the original field was indexed and you used a $match on that renamed field, it wouldn’t have used the index. Which in 3.6 addressed, making it use the index in these cases. Example code:-

        $project: {
          name: "$title"
        $match: {
          name: /^[aeiou]/i
        $count: "results"

Now, there is this question which followed the video which asked this question.

Chapter 5: Aggregation Framework Improvements

Aggregation Performance Improvements: Index Usage


True or False: For pipelines that rename fields, MongoDB 3.6 makes it possible to still use the underlying index. Renaming an existing field with $addFields will take advantage of this as well as automatic projection, while using a $project stage will not take advantage of automatic projection.

Now I would have answered TRUE, since $project and $addFields which allow you to a rename field, and still have the query planner use the orginal index, however what threw me, was the section

" while using a $project stage will not take advantage of automatic projection."

So I said FALSE, which was incorrect, it was a TRUE statement. So what does the “while using a $project stage will not take advantage of automatic projection.” actually mean.


PS - So, I know this course is old now, but it still teaches some important bits about MongoDB, which though in some cases has been superceeded, it added to my knowledge, things like Causal Consistency, how the retry mechanism worked, session ids, transaction id etc etc.

So, I am not sure it needs removing, since some of what it teaches is still valid.