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,
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.
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.
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.
MongoDB can use the multikey index to find documents that have 5 at any position in the ratings array.
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"})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With