Stable API does not support withTransaction method

Hey,

I am using Nodejs driver v6.2 to connect to mongoDB. I am trying to use the transactions as specified in example here https://github.com/mongodb-developer/nodejs-quickstart/blob/master/transaction.js.

The only difference is that I have modified the client connect code to use the stable version as below

const client = new MongoClient(uri, {
    serverApi: {
      version: ServerApiVersion.v1,
      strict: true,
      deprecationErrors: true,
    },
  });

With the above connection string, the Nodejs process fails to exit after executing the script.

Further I read about the changelog of stable API as specified in https://www.mongodb.com/docs/manual/reference/stable-api-changelog/#std-label-stable-api-changelog

But withTransaction, startTransaction methods are not included in the changelog.

If I change the strict param to false then I execute the script successfully and the nodejs process exists as well.

Any pointers that why Transactions are not working successfully with stable API ?

Hey @Asmita_atrey,

I tried modifying the sample you shared and didn’t have any issues:

const { MongoClient, ServerApiVersion } = require('mongodb');
// ...
async function main() {    
    // ...
    const client = new MongoClient(uri, {
      serverApi: {
        version: ServerApiVersion.v1,
        strict: true,
        deprecationErrors: true,
      },
    });
    // ...
}

I can confirm Stable API strict validation works as I tried adding a call to await client.db("admin").command({ replSetGetStatus: 1 }); right after client connection to see if it would fail, and it produces the desired failure:

MongoServerError: Provided apiStrict:true, but the command replSetGetStatus is not in API Version 1. Information on supported commands and migrations in API Version 1 can be found at https://dochub.mongodb.org/core/manual-versioned-api

Note that withTransaction isn’t a database command, but is an implementation of the Convenient API for Transactions specification, and startTransaction isn’t a database command either, but defining behavior on a client session object.

Do you have a specific error with a stack trace you can share?

Apologies, I misread the issue. What you’re experiencing is actually NODE-5748, which has nothing to do with transactions but would produce the behavior you described.

This is fixed in v6.3.0 of the driver.