MongoServerError

Node.jsMongoErrorserver

An error response received from the MongoDB server (as opposed to a driver-side error)

What is happening?

MongoServerError represents an error returned by the MongoDB server in response to a command. It contains a numeric error code (e.g. 11000 for DuplicateKey) and an error message. This is the driver's wrapper around server-side errors — check the code property to identify the specific error.

Common causes

  1. DuplicateKey (11000) — unique index violation
  2. Unauthorized (13) — insufficient privileges
  3. CommandNotFound (59) — unsupported command for the server version
  4. ExceededTimeLimit (262) — maxTimeMS exceeded
  5. WriteConflict (112) — concurrent write conflict in WiredTiger

Diagnostic Steps

Related Jira Issues

SERVER-138723Closed
Gracefully handle CE failing due to stale persisted samples
This can happen due to eg. a document with parallel arrays (wrt. an existing multikey index) existing in the persisted sample. We currently fail the query in this case, but can do better (eg. fall back to MP, retry with on-the-fly sampling, trigger a re-sample etc.). Repro: This fails with {{MongoServerError[Location10061118]: Parallel arrays are not supported}} Or this one: Which fails with {{MongoServerError[QueryPlanKilled]: query plan killed :: non-array path became multikey w
NODE-7832Backlog
Missing required sub-document 'driver' in the client metadata document when using jest
h3. Expected Behavior As a... Node Driver developer I expect... driver to load correctly when `require` is available but dynamic-import callback is not When... using driver 7.6 or higher h3. Actual Behavior and Impact * Current experience: `MongoServerError: Missing required sub-document 'driver' in the client metadata document` * This is incorrect and a red herring, forcing a user on a useless investigation * Workaround: setting `runtimeAdapters: \{ os: require('os') }` as a connect
NODE-5987Backlog
MongoServerError enumerable keys are duplicated by errorResponse
As a Node driver engineer, I want to store error information in exactly one place, So that we don't need to be responsible for maintaining the server information in two places. The server's actual error is stored both as the {{errorResponse}} field on the MongoServerError and has every property copied onto the server error (see https://github.com/mongodb/node-mongodb-native/blob/8ab5d19bee52bf1f0bc24a76586375a4825190f9/src/error.ts#L226). h3. Why this needs a major Typed error responses are b