Error in monogdb "errmsg": "WiredTigerIndex :: insert: key too large for indexing, failure
I am creating an index in mongo:
db.table.createIndex({"chr" : 1, "Start" : 1, "End" : 1, "Ref" : 1, "Alt" : 1})
It runs for a while and gives an error message:
error in monogdb "errmsg" : "WiredTigerIndex::insert: key too large to index, failing
How do I fix this error?
In MongoDB since version 2.6, the total index record size must be less than 1024 bytes. Documentation here
In other words, at least one of your documents is significant in one of the fields you are trying to index.
It is not a good idea in general to index very large values ββlike this, because it creates a large index that is less efficient compared to a smaller one, and takes up more RAM space that could be better used on a MongoDB node.
You can use this: mongod --setParameter failIndexKeyTooLong=false
.
But that doesn't sound like a good idea. If you have large text to index, you should consider using the Full Text index, or you can use the Hashed index.
It can also be caused by having both a text index and a standard index for the same field. By removing one of them, you should be able to fix this problem.