Mongodb. How to query the 10 records whose query time is closest to the current time

  mongodb, question

Now there is a requirement to check the latest 10 records.
Maybe we should rank the first 10 items first, but this is too slow.

I wonder if mongodb inserted the last record. Is it okay if I check the last 10?
Or how to query the last 10 records?

Mongodb does not specify sorting by default. It is sorted in ascending order of documents, so it does not meet your requirements. You need to sort to specify -1 of a field as descending order, and then limit10

In addition, if you feel slow, add an index.