Is there a way to specify the order of keys to sort by?
There seems to be some confusion in the comments. To be clear, I'm not asking about ascending or descending order. I'm asking if I can specify sorting priority.
For example, I want to sort by:
- pinned (Boolean)
- score (Number)
- newest (Date or ObjectId)
so that
- only docs with the same
pinnedvalue get sorted byscore, and - only docs with the same
pinnedandscoreget sorted bynewest?
In other words,
score,newestshould never be considered ifpinnedvalue is different (just sort bypinned)newestshould never be considered ifscoreis different.
For example,
{ pinned: false, score:1, _id: new }
{ pinned: true, score:1, _id: oldest }
{ pinned: false, score:2, _id: old }
should be ordered as
{ pinned: true, score: 1, _id: oldest }
{ pinned: false, score: 1, _id: new }
{ pinned: false, score: 2, _id: old }