Query failed: $or / $in / projection errors (BadValue) MongoDB Origin: Data OSI layer 7 · Application Last updated 5 Nov 2026

MongoServerError: Unknown modifier / unknown top level operator: $foo / Cannot use $in with a non-array

The query or update used an invalid operator or argument type.

Exact message you may see unknown top level operator: $fooMongoServerError: unknown operator: $foo$in needs an arrayUnknown modifier: $incrInvalid update operator: Update document requires atomic operators
Seen on: MongoDB

Meaning

The message names the bad operator. Fix typos ($inc vs $incr), ensure $in gets an array, don't mix inclusion and exclusion projections, wrap update fields in operators ($set), and don't update _id. Test the query in mongosh first.

Common causes

  • Misspelled operator ($gte, $set)
  • $in/$nin with non-array
  • Update document without $set mixing operators and fields
  • Mixing include/exclude projection
  • Modifying _id

⚡ Quick fix

  1. Check the exact operator name and argument type
  2. Use { $set: { field: value } } for updates
  3. Use only inclusion or only exclusion in projections

Detailed fix by platform

mongosh

  1. db.users.updateOne({ _id }, { $set: { name: "A" } })

How to diagnose

  1. Operator — Valid name?
  2. Type — Array where needed?
  3. Update — Uses $set?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

Atlas: bad auth: Authentication failed — MongoServerError: bad auth : Authentication failed. (Atlas user / special characters in password) (MongoDB)Atlas: bad auth: Auth…BSONObj size is invalid / exceeds maximum document size (16MB) — MongoServerError: BSONObj size: 17825792 (0x1100000) is invalid. Size must be between 0 and 16793600(16MB) (MongoDB)BSONObj size is inval…CursorNotFound: cursor id not found — MongoServerError: cursor id 1234567890 not found (CursorNotFound) (MongoDB)CursorNotFound: curso…Document failed validation — MongoDB: MongoServerError: Document failed validation (code 121) (MongoDB)Document failed valid…E11000 duplicate key — MongoServerError: E11000 duplicate key error collection: db.users index: email_1 dup key (Node.js)E11000 duplicate keyExecutor error: Sort exceeded memory limit (find().sort) — MongoServerError: Executor error during find command :: caused by :: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting (MongoDB)Executor error: Sort …Sort/Group exceeded memory limit of 100 MB (allowDiskUse) — MongoServerError: Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in (MongoDB)Sort/Group exceeded m…Query fai…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.