Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create index in mongodb, "key too large to index"

I am creating index in mongodb having 10 million records but following error

db.logcollection.ensureIndex({"Module":1}) {         "createdCollectionAutomatically" : false,         "numIndexesBefore" : 3,         "ok" : 0,         "errmsg" : "Btree::insert: key too large to index, failing play.logcollection.$Module_1 1100 { : \"RezGainUISystem.Net.WebException: The request was aborted: The request was canceled.\r\n   at System.Net.ConnectStream.InternalWrite(Boolean async, Byte...\" }",         "code" : 17282 } 

Please help me how to createindex in mongodb,

like image 930
Sandeep.maurya Avatar asked Jan 06 '15 05:01

Sandeep.maurya


People also ask

What is index key limit MongoDB?

Index Key The total size of an indexed value must be less than 1024 bytes. MongoDB will not add that value to an index if it is longer than 1024 bytes. Using db. collection.

How many index we can create in MongoDB?

Generally, MongoDB only uses one index to fulfill most queries. However, each clause of an $or query may use a different index, and in addition, MongoDB can use an intersection of multiple indexes.

Can we create index 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.

Does MongoDB support Multikey indexes?

MongoDB can use the multikey index to find documents that have 5 at any position in the ratings array.


1 Answers

MongoDB will not create an index on a collection if the index entry for an existing document exceeds the index key limit (1024 bytes). You can however create a hashed index or text index instead:

db.logcollection.createIndex({"Module":"hashed"}) 

or

db.logcollection.createIndex({"Module":"text"}) 
like image 188
anhlc Avatar answered Sep 21 '22 01:09

anhlc