MongoServerError: Index key too large to index (key size exceeds 1024 bytes) / pre-4.2 behaviour
A document has an indexed field whose value is too large for the index (limit 1024 bytes before MongoDB 4.2).
Index key too large to indexkey size exceeds the max limit 1024 bytesMongoServerError: Index key too large to index, failingWriteError: Btree::insert: key too large to index Meaning
MongoDB 4.2+ removed the limit for most cases (featureCompatibilityVersion 4.2+). On older versions don't index long strings: hash them ({field: "hashed"}), index a prefix or digest, or use text/search indexes. Check FCV with db.adminCommand({getParameter:1, featureCompatibilityVersion:1}).
Common causes
- Long string field in an index (URLs, text)
- FCV below 4.2
- Compound index sum of key sizes too big
- Importing long values
- Old server version
⚡ Quick fix
- Use a hashed index or index a shortened/derived field
- Upgrade and set FCV 4.2+
- Remove the index from the large field
Detailed fix by platform
mongosh
db.pages.createIndex({ url: "hashed" })
How to diagnose
- FCV — Version?
- Field — Long text?
- Alternative — Hashed index?
🔧 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)
- createIndex failed: unique index with duplicates MongoServerError: Index build failed: E11000 duplicate key error collection: db.users index: email_1 dup key
Most viewed in MongoDB
- Document failed validation MongoDB: MongoServerError: Document failed validation (code 121)
- 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)
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