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;}
}
When I store one UserSearch item, my collection have _id and default index on it.
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_");
}
Any suggestion/solution?
Starting in MongoDB 5.2, you can use db. collection. dropIndex() to drop existing indexes on the same collection even if there is a build in progress on another index.
According to MongoDB documentation: Normally, MongoDB compacts indexes during routine updates. For most users, the reIndex command is unnecessary. However, it may be worth running if the collection size has changed significantly or if the indexes are consuming a disproportionate amount of disk space.
Indexes store references to fields in either ascending ( 1 ) or descending ( -1 ) sort order. For single-field indexes, the sort order of keys doesn't matter because MongoDB can traverse the index in either direction.
MongoDB provides two geospatial indexes known as 2d indexes and 2d sphere indexes using these indexes we can query geospatial data.
You can't delete the _id
index once created. However you can create a collection without _id
indexes by setting the autoIndexId
option to false
using db.createCollection
but without _id
you can't replicate your collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With