I was looking for the way how to get a maximum value from a MongoDB collection, and I've found most of people recommend to sort first, and then get the first one from the result.
In general, sorting takes O(NlogN) time, but if the field that I want to sort is already indexed, it should take much less time.
So my question is,
- As I wrote in the title, does sort() of MongoDB run in O(1) time?
- If not, does MongoDB provide a faster way to get the max value?