MongoDB Index for sorting by Date

  Kiến thức lập trình

I have a simple question – maybe too simple so that I don’t find an answer:

My collection has documents containing a field startTimestamp of type date. The UI shows the documents in descending order of startTimestamp, so I just order by date:

db.mycollection.find( {} ).sort( {startTimestamp: -1} );

As the collection starts to grow, the query gets slower and slower.

I can not figure out, if I really need an Index for that field? If so, are there any disadvantages?

I tried to create an index but was not sure if the query time gets faster

New contributor

Björn Konrad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.