Cannot create index in mongodb, “key too large to index”

后端 未结 5 746
旧时难觅i
旧时难觅i 2020-12-01 10:29

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

db.logcollection.ensureIndex({\"Module\":1})
{
        \"createdCollectionAutom         


        
5条回答
  •  庸人自扰
    2020-12-01 11:01

    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"})
    

提交回复
热议问题