ESR rule: What if my sorting and range index is same?

Hi Community,

I am planning to include indexes to make my query faster, currently working on Springboot.

I have variables userType and creationStamp (current date and time in epoch milli). Currently my collections have no indexes and all queries have these two common variables, default sorting being done on creationStamp- which makes the query very slow as all its values are unique.

I have to introduce a new variable date (which won’t have timestamp). My idea is to use a compound index with order {userType, date} as range follows equality but I’m not sure how sorting would be done in this case. Are the documents sorted by the order they are saved in the collection? If not, how should I approach this problem if I want the sorted order to be in descending order of date and time of getting saved in the collection?

Thank you.