且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以删除默认的MongoDB索引吗?

更新时间:2023-12-05 20:35:58

不,你不能删除它。

来自 MongoDB文档,强调我的;


_id索引

The _id Index

对于除上限集合之外的所有集合,索引是为_id字段自动创建的
。此索引是特殊的,
无法删除 。 _id索引强制其键
的唯一性(除了某些带分片的情况)。

For all collections except capped collections, an index is automatically created for the _id field. This index is special and cannot be deleted. The _id index enforces uniqueness for its keys (except for some situations with sharding).