7

I'm creating a index in mongo:

db.table.createIndex({"chr" : 1, "Start" : 1, "End" : 1, "Ref" : 1, "Alt" : 1}) 

It runs for some time and gives an error msg:

error in monogdb "errmsg" : "WiredTigerIndex::insert: key too large to index, failing

How do I fix this error?

SiHa
  • 7,830
  • 13
  • 34
  • 43
  • Hi @anop.perl, can you add some details ? for instance, is the `table` collection already populated ? – danidemi Apr 11 '17 at 10:00
  • Possible duplicate of [Cannot create index in mongodb, "key too large to index"](https://stackoverflow.com/questions/27792706/cannot-create-index-in-mongodb-key-too-large-to-index) – OhadR Jan 08 '19 at 09:23

2 Answers2

11

In MongoDB, since 2.6, the total size of an index entry must be less than 1024 bytes. Documentation here

In other terms, at least one of your documents has a large value in one of the field you are trying to index.

It's not a good idea in general to index very large values like that because it creates a big index which is less efficient compared to a smaller one and it takes more space in RAM which could be put to better use on a MongoDB node.

You could use this : mongod --setParameter failIndexKeyTooLong=false.

But it doesn't look like a good idea. If you have a large text to index, you should consider using the Full Text index or you could use a Hashed index.

Maxime Beugnet
  • 822
  • 5
  • 10
0

This can also be caused by having both a text index and a standard index for the same field. By deleting one of them you will be able to resolve this issue.

Gabriel Fair
  • 4,081
  • 5
  • 33
  • 54