我可以删除默认的MongoDB索引吗? [英] Can i delete default MongoDB Index?
问题描述
我有一个集合,我不需要任何索引。我只存储用户搜索字词和日期,所以我的收藏非常简单。
I have one collection for which I don't need any index. I just store user search term and date, so my collection is really simple.
class UserSearch {
public string Term {get; set;}
pulic DateTime Date {get;set;}
}
当我存储一个UserSearch项时,我的集合上有_id和默认索引。
When I store one UserSearch item, my collection have _id and default index on it.
据我所知,那些_id字段将在ram中编入索引,所以我不想花ram内存进行收藏,我只是存储,而且我每12小时计算一次。
From my knowledge, those "_id" fields will be indexed in ram, so I don't want to spend ram memory for collection which I just store and I'm calculating something every 12 hours.
我试着删除它,但是我不能。
I try to delete it, but I can't.
var indexes = UserSearch(true).GetIndexes();
//delete UserSearch Default Index
if(UserSearch(true).IndexExistsByName("_id_"))
{
UserSearch(true).DropIndexByName("_id_");
}
任何建议/解决方案?
推荐答案
不,你不能删除它。
来自 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).
这篇关于我可以删除默认的MongoDB索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!