[DRIVERS-724] Sessions V2 Created: 19/Aug/19  Updated: 31/Mar/22

Status: Backlog
Project: Drivers
Component/s: None
Fix Version/s: None

Type: Epic Priority: Major - P3
Reporter: Esha Bhargava Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to NODE-3423 Problem with session.getDatabase Closed

 Comments   
Comment by Kaitlin Mahar [ 12/Jul/21 ]

Linking NODE-3423, a user discusses in the comments there how they prefer the shell API over the driver one.

Comment by Kræn Hansen [ 27/Jul/20 ]

At the very least a session instance should expose CRUD operations on the database which is always ensured to run in the context of the session.

For context, I was trying to run a data-migration script and I was very surprised that the insertOne operation was not running in the context of the session / transaction and I instead had to pass it explicitly via the options object:

async function runMigration() {
  const client = await MongoClient.connect(MONGO_CONNECTION_STRING, {
    useUnifiedTopology: true,
  });
  const db = client.db(MONGO_DB_NAME);
  await client.withSession((session) => {
    return session.withTransaction(async (session) => {
      const migrations = db.collection("Migrations");
      await migrations.insertOne({ test: "123" }, { session }); // What if I forget this options object?
      throw new Error("Abort!");
    });
  });
}

Generated at Thu Feb 08 08:22:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.