connect-mongo
connect-mongo copied to clipboard
Proposal for https://github.com/jdesboeufs/connect-mongo/issues/472
- 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
Hello Team, please review and let me know your thoughts on this.
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.