How can I get a newest collection records?

With SQL and incremental id I could just compare by id.
Mongo also has sortable objectId but there is one nuance:

While ObjectId values should increase over time, they are not necessarily monotonic. This is because they:

  • Only contain one second of temporal resolution, so ObjectId values created within the same second do not have a guaranteed ordering, and
  • Are generated by clients, which may have differing system clocks.

In my case clients don’t generate objects but the first part is still important.
At the very beginning I thought about comparing by createdAt, but also had worry about posibility of multiple records with the same value of createdAt (even if its resolution in ms). I’m pretty sure that is very unlikely but my inner perfectionist is suffering. So I thought to send info about latest current record from client: createdAt (for gte comparing) and objectId (filter it from result).

May be you know more simple solution for such common task.

Parse Server does not use the MongoDB object id default implementation and as long as I know you cannot rely on Parse object id to sort by creation date. I’d go just with createdAt, but you can also use objectId to make sure that two objects with the same createdAt value will be ordered always in the same way.