14 — TypeMismatch

queryconfiguration

A value has the wrong BSON type for the operation

What is happening?

TypeMismatch is returned when an operation encounters a value whose BSON type does not match what the operation expects. This can happen in query predicates, update operators, index key generation, or command arguments. For example, applying $inc to a string field, or using $regex on a numeric field.

Common causes

  1. Applying an arithmetic update operator ($inc, $mul) to a non-numeric field
  2. Query predicate type incompatible with the operator (e.g. $regex on a number)
  3. Schema changed and old documents contain a different type for the same field
  4. Aggregation expression receives an unexpected type from upstream stages
  5. Index build fails because a document field has a type the index does not support

Source code references

ErrorCodes::TypeMismatch found in 170 locations in the MongoDB server source.

Diagnostic Steps