I can drop the newly created indexes, but there is no trashcan icon to delete the main index. Is there a way to do this in Compass? Or is this a shell only feature. MongoDB manual says “Click Drop to drop the index.” which doesn’t answer the question.
You can not remove this index…from the documentation:
Default _id
Index
MongoDB creates a unique index on the _id field during the creation of a collection. The _id
index prevents clients from inserting two documents with the same value for the _id
field. You cannot drop this index on the _id
field.
1 Like
Does that mean when you run the command .dropIndexes() in the shell, it also doesn’t drop the _id index? It seems like it does.
I just tested it on my local MongoDB instance (4.2.7)
> db.add.dropIndex({"_id": 1})
{
"ok" : 0,
"errmsg" : "cannot drop _id index",
"code" : 72,
"codeName" : "InvalidOptions"
}
> db.add.dropIndexes()
{
"nIndexesWas" : 1,
"msg" : "non-_id indexes dropped for collection",
"ok" : 1
}
> db.add.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "address.add"
}
]
It drops all “non _id” indexes.
3 Likes
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.