Is there an equivalent of _id.getTimestamp() for updated_at records?

As we can identify the creation date by the calling the method getTimestamp() from the _id object, is there an equivalent to get the updated_at (like in mongoose) ?

I am working with mongodb driver 4.11.0 in nodejs v16.

Hi @Guillaume_Pestre,

ObjectId.getTimestamp() returns the timestamp portion of an ObjectId() (which is added when an ObjectId is generated) as a Date.

If I understand your question correctly, you are asking if there is a method to get an updated_at timestamp from a document without adding any extra fields or using a helper library like Mongoose? If so, the answer is no: you must add and maintain any additional timestamp fields in your application code.

Mongoose schemas support a Timestamps option which takes care of the housekeeping of adding an explicit createdAt field and refreshing an updatedAt field as long as document updates go via a supported Mongoose method call. The MongoDB server currently (as at 6.0) does not have any notion of an updated_at timestamp for a document.



Hello Stennie,

Thank you very much for the feedback.

We are not using mongoose because in our cases, mongodb driver is faster to process. So has you said, we will add it directly into our schema.