Are indexes required for the current (7x) version of MongoDB when you created a capped collection?
While trying to figure out what size
I should have given my known max documents I created a quick test collection that was supposed to hold some values, so I could get some idea on how big each document would be.
db.createCollection("gts", {capped: true, max: 5, size: 1024, autoIndexId: false})
I then check the indexes and see that it created an index on the _id field anyway.
For those curious about why I do not need the index, my goal is to set up a sample collection that
- focuses on handling mostly high write throughput
- I do not care much about the insertion order, just that it holds roughly the newest
- I want a max set of most “recent” metrics, hence capped collection. I will combine it with max documents
- I will never update or delete records, only write and have them be replaced with newer metrics
- Reads will not be frequent, maybe max twice a day
- When I do read, it will be a collection scan regardless, since I will be doing the sum of all samples.
The end goal of that is to have a collection I can use to sample the “average of recent”. I do not want to use TTL either, because I want the known N most recent (when the collection reaches the cap), so a fixed size is plenty good.
This is why I do not really need the _id either, but I read that it’s good for replica sets, which I am using. Other than that the _id field is not really needed for me.
Suggestions are welcome too of course.