MongoDBSessionInterface to use the default database name in connection URI #259
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
I have been using flask-sessions for session management and encountered an inconvenience while setting up MongoDBSessionInterface. When configuring a MongoDB client with a connection URI, the database name must be provided separately even though it is included in the URI. This leads to redundant and less intuitive code.
In the MongoDB world, it is typical to configure the connection using a URI, which includes all necessary details such as the host, port, and database name. This simplifies the configuration process.
Current Implementation:
To use MongoDB as a session store, the current implementation requires creating a MongoClient and then explicitly providing the database name again when initializing MongoDBSessionInterface:
In contrast, the setup for using Redis as a session store is more straightforward and requires fewer steps:
Proposal:
Allow MongoDBSessionInterface to extract the database name directly from the MongoClient if the database name is included in the URI:
This enhancement would align the MongoDB configuration/initialization process more closely with that of Redis etc and improve the developer experience, leveraging the typical MongoDB configuration practice of using a connection URI.
Thanks.