In aggregation pipeline its clear how the order will be.
Besides aggregation we have 2 other database commands
Find command can have sort,limit,skip,project,query
Count command can have query,limit,skip.
When you give to the driver something like the bellow(a driver method call)
MongodDB will see a command that will look like bellow
id: new Binary(Buffer.from("c686ad6eb9f140649cefed4ea6f10708", "hex"), 4)
It will ignore the sort and the project,and just send a count-command(they dont make sense anyways) to monodb.
If you dont put the count in the end,driver will send 1 find command to mongodb
No matter the order you give,the order is defined by the find command.
For example sort is done before limit which make sense see here
Aggregate/Find methods are lazy,you say what you want to do,with cursor methods,
but nothing goes to the database,when its needed for example you asked for results,
driver will take all that info,create a command,that will run and you will get the results.