Skip to content

Using Promise.all inside transactions errors with "Cannot pin multiple connections to the same session" #14603

Closed

Description

Prerequisites

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

Mongoose version

8.4.0

Node.js version

22.0.0

MongoDB server version

7.3.2

Typescript version (if applicable)

No response

Description

Using running mongo queries/commands in Promise.all wrapped in a transaction throws the following error:

TypeError: Cannot pin multiple connections to the same session

I tested this using an atlas serverless database. Is it not allowed to run queries in parallel when using a transaction?

Steps to Reproduce

import mongoose from 'mongoose';
mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/transaction-test');

const userSchema = new mongoose.Schema({
  name: String,
});

const User = mongoose.model('User', userSchema);

test('user transaction test', async () => {
  await Instance.db.transaction(async session => {
    return Promise.all([
      User.findOne({}, null, { session }),
      User.findOne({}, null, { session }),
    ]);
  });
});

Expected Behavior

No error.

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

Metadata

Assignees

No one assigned

    Labels

    underlying library issueThis issue is a bug with an underlying library, like the MongoDB driver or mongodb-core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions