Skip to content

MongoDB: Command failed (OperationNotSupportedInTransaction): Cannot run command against the 'admin' database in a transaction. #7967

Open

Description

@janpio

The default Mongo connection string you get from DigitalOcean's hosted MongoDB offering looks like this: mongodb+srv://doadmin:[email protected]/admin?authSource=admin&replicaSet=db-mongodb-nyc3&tls=true&tlsCAFile=../ca-certificate.crt.

When you try to run a query on that, you get an error message like this:

PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: 
Invalid `prisma.user.deleteMany()` invocation:
  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawError { code: "unknown", message: "Command failed (OperationNotSupportedInTransaction): Cannot run command against the 'admin' database in a transaction.)" } })
    at cb (/home/runner/work/e2e-tests/e2e-tests/databases/mongodb-digitalocean/node_modules/@***/client/runtime/index.js:33904:17)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  clientVersion: '2.27.0-dev.6'
}

Turns out there is a limitation around default databases like admin for using transactions. We should handle that somehow.

Activity

  1. matthewmueller commented on Jul 1, 2021

    @matthewmueller
    Contributor

    Planning Notes:

    New MongoDB instances come with 4 collections:

    • Can't run transactions on the system collections for some reason.
    • Weird that DO defaults to one of the system collections.

    Workaround:

    • MongoDB creates collections on the fly (change to admin1)

    Improvements to consider for now

    • Better error
    • Add Documentation
  2. added this to the 2.27.0 milestone on Jul 1, 2021
  3. janpio commented on Feb 17, 2022

    @janpio
    ContributorAuthor

    Suggestion: Better error that knows about the system databases and helps you to understand the failure and offers a solution: Change the database name to something that is not a system database and can use transactions.

  4. pinchez254 commented on Apr 7, 2022

    @pinchez254

    creating a separate db with a different name worked for me. Avoid using primary DBs with reserved names such as admin or root

  5. removed their assignment
    on Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions