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.
unknown top level operator: $fooMongoServerError: unknown operator: $foo$in needs an arrayUnknown modifier: $incrInvalid update operator: Update document requires atomic operators 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/$ninwith non-array- Update document without
$setmixing operators and fields - Mixing include/exclude projection
- Modifying
_id
⚡ Quick fix
- Check the exact operator name and argument type
- Use
{ $set: { field: value } }for updates - Use only inclusion or only exclusion in projections
Detailed fix by platform
mongosh
db.users.updateOne({ _id }, { $set: { name: "A" } })
How to diagnose
- Operator — Valid name?
- Type — Array where needed?
- 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:
Similar errors
- Atlas: bad auth: Authentication failed MongoServerError: bad auth : Authentication failed. (Atlas user / special characters in password)
- BSONObj size is invalid / exceeds maximum document size (16MB) MongoServerError: BSONObj size: 17825792 (0x1100000) is invalid. Size must be between 0 and 16793600(16MB)
- CursorNotFound: cursor id not found MongoServerError: cursor id 1234567890 not found (CursorNotFound)
Most viewed in MongoDB
- MongoParseError MongoDB: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
- bad auth : Authentication failed MongoDB: MongoServerError: bad auth : Authentication failed (code 8000 / 18)
- StrictPopulateError: Cannot populate path because it is not in your schema Mongoose 6+: StrictPopulateError: Cannot populate path `author` because it is not in your schema
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 5 Nov 2026