Hello
In aggregation pipeline its clear how the order will be.
Besides aggregation we have 2 other database commands
1)find command
2)count command
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)
db.solarSystem.find({},{name:1,_id:0})
.skip(1)
.limit(2)
.sort({name:1})
.count()
MongodDB will see a command that will look like bellow
{
count: 'solarSystem',
query: {},
limit: 2,
skip: 1,
lsid: {
id: new Binary(Buffer.from("c686ad6eb9f140649cefed4ea6f10708", "hex"), 4)
},
'$db': 'solar'
}
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.