72
MongoDBERRORNotableQuery ErrorHIGH confidence

The command was given invalid options

What this means

This error indicates that an option or parameter provided to a database command is not valid, is of the wrong type, or is unrecognized. It is a generic error for misconfigured command arguments.

Why it happens
  1. 1Providing an unknown option to a command (e.g., `uniquee: true` instead of `unique: true`)
  2. 2Giving a value of the wrong data type for an option (e.g., `limit: '10'` instead of `limit: 10`)
  3. 3Using an option that is not supported by the specific command being run
  4. 4A typo in an option name in a helper method like `find().sort()`
How to reproduce

A `createIndex` operation is called with a misspelled option.

trigger — this will error
trigger — this will error
// The option is 'unique', not 'uniqe'.
db.collection.createIndex({ field: 1 }, { uniqe: true });

expected output

MongoServerError: The 'uniqe' option is not a valid index option.

Fix 1

Correct the Option Name or Value

WHEN The error is due to a typo or incorrect value.

Correct the Option Name or Value
// Corrected command with the proper option name.
db.collection.createIndex({ field: 1 }, { unique: true });

Why this works

Carefully review the command and its options against the official MongoDB documentation. Check for spelling mistakes and ensure all values have the correct data type.

Fix 2

Check Driver and Server Version Compatibility

WHEN An option seems correct according to the documentation.

Why this works

Sometimes a driver might expose an option that is only available in a newer version of MongoDB. Ensure your driver version is compatible with your server version, and that the option is supported by both.

What not to do

✕ Remove the option to make the error go away

The option was likely there for a reason (e.g., to enforce uniqueness or set a write concern). Removing it changes the behavior of the command and may introduce bugs or data integrity issues.

Sources
Official documentation ↗

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

Database Command Reference ↗

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

← All MongoDB errors