125
MongoDBERRORGenericLOW confidence

The command has failed

What this means

This is a generic error wrapper used by older drivers and shells. It indicates that a command failed, but the actual, more specific error code and message are nested inside the error response object.

Why it happens
  1. 1This is a wrapper error. The true cause is in the nested error document.
  2. 2An older MongoDB driver or `mongo` shell might report this instead of the specific error code.
  3. 3Any command failure could be wrapped in this error.
  4. 4For example, a `DuplicateKey` error (11000) might be presented as a `CommandFailed` error (125).
How to reproduce

This is a presentation-layer error. Any command can trigger it. For example, a duplicate key insert might be reported this way by an older client.

trigger — this will error
trigger — this will error
// A command that causes a more specific error.
db.users.createIndex({ email: 1 }, { unique: true });
db.users.insertOne({ email: "test@example.com" });
db.users.insertOne({ email: "test@example.com" });

expected output

// An older client might show:
CommandFailed: E11000 duplicate key error ...

Fix 1

Inspect the Nested Error Object

WHEN You receive this error code.

Why this works

Look at the full error response from the driver. It will contain a `code` or `errInfo` field with the true, specific error code (like 11000) and a more detailed message. This is the real error you need to debug.

Fix 2

Update Your MongoDB Driver

WHEN You consistently see this generic error instead of specific ones.

Update Your MongoDB Driver
// For Node.js
npm update mongodb

Why this works

Modern MongoDB drivers are better at unwrapping this error and presenting the specific underlying cause directly. Updating your driver can improve the debugging experience.

What not to do

Write application logic that only checks for code 125

This is too generic. Your error handling logic should be based on the specific, nested error code (e.g., 11000 for duplicates, 112 for write conflicts) to react appropriately.

Sources
Official documentation ↗

mongodb/mongo src/mongo/base/error_codes.yml

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MongoDB errors