At what is referencing "sortKey" in Chapter 4, Lecture Manual Buckets

Hello,

I tried to understand the bucket command from the output of the explain, but I don’t get what is happening in this sort:

{
      "$sort" : {
        "sortKey" : {
          "_id" : 1
        }
      }
}

Is it similar to sortKey._id : 1 and who is sortKey?

Hi @Aida_Camara, welcome to the community :wave: .

This is a format used by the query planner after interpreting the query. This has nothing to do with

The sort expression written in the aggregation pipeline: { $sort: { _id: 1 } } is used to sort the results whereas the above syntax by .explain() is just for describing the stage.

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

1 Like

I got it! Thank you for the explanation!