Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 637
Anop Singh Ranawat Avatar asked Apr 11 '17 09:04

Anop Singh Ranawat


People also ask

Which of the following is the correct syntax for using an index in MongoDB?

Syntax. The basic syntax of createIndex() method is as follows(). Here key is the name of the field on which you want to create index and 1 is for ascending order. To create index in descending order you need to use -1.

Which index Cannot be deleted in MongoDB?

You cannot drop the default index on the _id field. Starting in MongoDB 4.2, you cannot specify db. collection. dropIndex("*") to drop all non- _id indexes.

What does createIndex do in MongoDB?

The indexes are ordered by the value of the field specified in the index. So, MongoDB provides a createIndex() method to create one or more indexes on collections. Using this method we can create different types of indexes like text index, 2dsphere index, 2d index, etc.

Why index is not used in MongoDB?

Indexes support the efficient execution of queries in MongoDB. Without indexes, MongoDB must perform a collection scan, i.e. scan every document in a collection, to select those documents that match the query statement.


1 Answers

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.

like image 144
Maxime Beugnet Avatar answered Sep 20 '22 03:09

Maxime Beugnet