While saving a collection MongoDB is creating Index name which is too long and exceeds 127 bytes limit. How to solve this. can i disable indexing?

后端 未结 2 2198
醉酒成梦
醉酒成梦 2021-02-20 10:25
com.mongodb.CommandFailureException: { \"serverUsed\" : \"localhost:27017\" , \"createdCollectionAutomatically\" : true , \"numIndexesBefore\" : 1 , \"ok\" : 0.0 , \"err         


        
相关标签:
2条回答
  • 2021-02-20 11:07

    You can not disable indexing as MongoDB will always create an index for _id. Shorten your collection name instead - saves you some typing too

    0 讨论(0)
  • 2021-02-20 11:11

    You can pass an index name as parameter to ensureIndex:

    db.collection.ensureIndex({"birds.parrots.macaw.blue.id": 1}, {name:"myIndex1"});
    
    db.collection.ensureIndex({"birds.parrots.macaw.blue.id": 1, "field2": 1}, {name:"myIndex1"});
    
    0 讨论(0)
提交回复
热议问题