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

标签 mongodb indexing nosql

我有一个不需要任何索引的集合。我只存储用户搜索词和日期,所以我的收藏非常简单。

class UserSearch {

public string Term {get; set;}
pulic DateTime Date {get;set;}

}

当我存储一个 UserSearch 项目时,我的集合上有 _id 和默认索引。

据我所知,那些“_id”字段将在 ram 中编制索引,因此我不想将 ram 内存用于收集,我只是存储并且每 12 小时计算一次。

我尝试删除它,但我不能。

   var indexes = UserSearch(true).GetIndexes();

   //delete UserSearch Default Index
   if(UserSearch(true).IndexExistsByName("_id_"))
   {
     UserSearch(true).DropIndexByName("_id_");
   }

有什么建议/解决方案吗?

最佳答案

不,你不能删除它。

来自 MongoDB documentation , 强调我的;

The _id Index

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).

关于mongodb - 我可以删除默认的 MongoDB 索引吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12438958/

相关文章:

node.js - 如何在 ReactJS 中显示来自 MongoDB 的图像

mongodb 通过比较字段值查找

mysql - 对 UUID 主键使用字符串类型与 uuid 类型相比,对性能有何影响?

sql-server - 由于计划不当或索引碎片化,MS SQL 查询速度变慢

performance - 具有多个相同列索引的 Oracle 性能

python - 混合 PostgreSQL 和 MongoDB(作为 Django 后端)

node.js - 如何增加 Mongoose 中子文档的属性?

mongodb - 有没有一个好的库可以让 Kotlin 协程异步访问 Mongo?

php - 我可以使用 MongoDB 在 Symfony 2 中存储 session 吗?

ruby-on-rails - 无架构数据库 : Indexing dynamically-typed things by their properties?