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.