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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withSession() function #14330

Closed
2 tasks done
marosstruk opened this issue Feb 2, 2024 · 1 comment 路 Fixed by #14339
Closed
2 tasks done

Add withSession() function #14330

marosstruk opened this issue Feb 2, 2024 · 1 comment 路 Fixed by #14339
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Milestone

Comments

@marosstruk
Copy link

marosstruk commented Feb 2, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

馃殌 Feature Proposal

Add withSession() function that would handle session's object lifetime. It should be analogous to the withTransaction() function.

For more details, see MongoDB driver documentation: https://mongodb.github.io/node-mongodb-native/6.3/classes/MongoClient.html#withSession

Motivation

There are two reasons why I believe withSession() function is required:

  1. Ease of use

    • Currently, to use a session, it is required to call two functions (startSession, endSessions) and handle any potential exceptions with a catch statement.
    • It would be much more convenient for most use-cases to have this logic abstracted to an out-of-the-box function.
  2. Consistency

    • There already is withTransaction function that handles transaction lifecycle, so it is natural to expect there to be a similar function for the session object.

Example

No response

@marosstruk marosstruk added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class labels Feb 2, 2024
@vkarpov15
Copy link
Collaborator

Are you using sessions without transactions? If so, what's your use case?

@vkarpov15 vkarpov15 added this to the 8.2 milestone Feb 2, 2024
@IslandRhythms IslandRhythms linked a pull request Feb 7, 2024 that will close this issue
vkarpov15 added a commit that referenced this issue Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants