Skip to content

Add withSession() function #14330

Closed
@marosstruk

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new featurenew featureThis change adds new functionality, like a new method or class

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions