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 2168
醉酒成梦
醉酒成梦 2021-02-20 10:25
com.mongodb.CommandFailureException: { \"serverUsed\" : \"localhost:27017\" , \"createdCollectionAutomatically\" : true , \"numIndexesBefore\" : 1 , \"ok\" : 0.0 , \"err         


        
2条回答
  •  无人及你
    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"});
    

提交回复
热议问题