Sunday 2 April 2017

How to get previous ObjectId based on given ObjectId

I have an ObjectId of a certain document in mongodb, for example: ObjectId("5741f9e489d23b39034aa450").

I would like to know the previous id 'in line', e.g. for the above id it would be: ObjectId("5741f9e489d23b39034aa44f") (notice the last two characters).

How can I calculate that using javascript?

Note: I only care about the objectId string, no need to require any library, just string / math / regex manipulations (if possible) please.

Thanks



via Or A.

No comments:

Post a Comment