com.mongodb.CommandFailureException: { \"serverUsed\" : \"localhost:27017\" , \"createdCollectionAutomatically\" : true , \"numIndexesBefore\" : 1 , \"ok\" : 0.0 , \"err
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"});