I have created multiple documents inside my collection that has the “name” field set to a unique index. The issue I am having is that when I remove “name” as a unique index, it still requires the field to be unique. How can I remove the unique index of a field without removing the field from my documents?
Welcome @Jon_Paricien
Can you post the error on inset and the indices on the collection?
A collection names with name as field:
{
_id: 1,
name: "John Doe",
profession: "Programmer"
}
Create a unique index on name field:
db.names.createIndex( { name: 1 }, { unique: true } )
List all indexes on the collection:
db.names.getIndexes()
Remove the index on name field using the dropIndex method:
db.names.dropIndex( { name: 1 } )
The above commands work from the mongo Shell. The same actions can be performed from the Compass GUI tool.
4 Likes