Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CarlosLunaGit
Copy link

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

Based on #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
Copy link
Author

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

@ilias-t
Copy link

ilias-t commented Oct 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants