How does mongodb get the last updated batch of data in the collection?

  mongodb, question

There should be a problem with the presentation of the title. But I don’t know how to describe it simply.

The situation is that a collection will update a batch of data every few days, and they all have a unified time stamp for the day.
Is there a more efficient way to directly obtain all records with the latest timestamp?

The current handling method is
collection.find().sort(‘timestamp’, pymongo.DESCENDING).limit(1)
Get a latest timestamp

And then in
Find ({timestamp’: latest timestamp})

I always feel that I have seen a more concise writing style somewhere.
Ask for help.

Considering the efficiency and difficulty, I think there is no problem with your writing this way. Besides, I have not come up with a particularly good alternative. I don’t know if the “more concise” writing you said is the group+$push writing in the aggregation. If so, the writing method is not as efficient as it is now, and there is a possibility of abnormality when the result is too large.
However, there are some additional issues I would like to explain. Even a batch of updated data,timestampNot necessarily the same; Or not a batch of updated documentstimestampNot necessarily different. To distinguish the concept of “batch update”, documents updated in the same batch must have a unique “batch number”, which can beObjectIdOrGUID. proposalObjectIdIt is relatively short, so its performance is slightly better.