connect-mongo icon indicating copy to clipboard operation
connect-mongo copied to clipboard

Proposal for https://github.com/jdesboeufs/connect-mongo/issues/472

Open CarlosLunaGit opened this issue 2 years ago • 2 comments
trafficstars

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Based on https://github.com/jdesboeufs/connect-mongo/issues/472 we wonder; how to add createdAt and updatedAt timestamps to the MongoDB documents for better tracking and auditing?

  • What is the current behavior? (You can also link to an open issue here)

createdAt and updatedAt do not exist, current data schema: type InternalSessionType = { _id: string session: any expires?: Date lastModified?: Date }

  • What is the new behavior (if this is a feature change)?

createdAt and updatedAt exist and are pushed to the MongoDB under the following schema: type InternalSessionType = { _id: string session: any expires?: Date lastModified?: Date createdAt?: Date updatedAt?: Date }

  • Other information:

The main code changes are in the set method of the MongoStore class. This method is responsible for both creating and updating sessions. The createdAt field is initialized when a new document is created, and the updatedAt field is updated whenever an existing document is updated.

  • Checklist:

  • [] Added test cases

  • [] Updated changelog

CarlosLunaGit avatar Oct 22 '23 07:10 CarlosLunaGit

Hello Team, please review and let me know your thoughts on this.

CarlosLunaGit avatar Oct 22 '23 07:10 CarlosLunaGit

Thanks for this! No comment on the implementation, but from a usability perspective I'd also suggest having this be configurable via a parameter in the initialization object, for example something like { timestamps: true }. The default value could be false so that this change is purely opt-in.

ilias-t avatar Oct 23 '23 19:10 ilias-t