我有一个不需要任何索引的集合。我只存储用户搜索词和日期,所以我的收藏非常简单。
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/