Index key too large to index MongoDB Origin: Data OSI layer 7 · Application Last updated 5 Nov 2026

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).

Exact message you may see 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
Seen on: MongoDB

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

  1. Use a hashed index or index a shortened/derived field
  2. Upgrade and set FCV 4.2+
  3. Remove the index from the large field

Detailed fix by platform

mongosh

  1. db.pages.createIndex({ url: "hashed" })

How to diagnose

  1. FCV — Version?
  2. Field — Long text?
  3. 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:

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…createIndex failed: unique index with duplicates — MongoServerError: Index build failed: E11000 duplicate key error collection: db.users index: email_1 dup key (MongoDB)createIndex failed: u…E11000 duplicate key — MongoServerError: E11000 duplicate key error collection: db.users index: email_1 dup key (Node.js)E11000 duplicate keyEMFILE — Too many open files (EMFILE) (Linux)EMFILEfork: retry: Resource temporarily unavailable — fork: retry: Resource temporarily unavailable (process/thread limit) (Linux)fork: retry: Resource…mongod: Too many open files (ulimit warning) — MongoDB: WARNING: soft rlimits too low. Number of files is 1024, should be at least 64000 / Too many open files (MongoDB)mongod: Too many open…MongoDB Atlas: connection timed out — IP not whitelisted — MongoServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted (MongoDB)MongoDB Atlas: connec…Index key…

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.