Reputation: 53
I have a collection with half billion of records. Every second inserting avg 100 docs on it. It has index on datetime field, which size about 5 GB.
"created" : ISODate("2020-01-01T12:48:51.671Z")
So, quection is - if I create field of value of rounded datetime by minute, will it use less storage for this index?
I mean, every record will have field with value, for eg:
"created" : ISODate("2020-01-01T12:48:00Z")
UPDATED:
I tested in collection with about 20m docs. Results:
"_id_" : 221757440,
"created" : 210997248,
"created_rounded" : 97366016
Upvotes: 4
Views: 1138
Reputation: 1378
Quick answer, YES!
The format of Date in the mongoDb is constant and no matter how much data you want to put in. The allocated memory is not changing.
BSON Date is a 64-bit integer that represents the number of milliseconds since the Unix epoch (Jan 1, 1970).
UPDATE:
The indexes are something like {key1: [value1, value2]}. Then if you round the date field that you mentioned, it will create less key
and in the end, your answer is YES.
Upvotes: 1