MongoDB Date Indexing – Best Practices for Indexing a Date Field in MongoDB

indexmongodb

Hi We would like to index a date field on a potentially large collection.
Is indexing a date-time field a good practice? Or should we stick to a date field (e.g. 07/12/2017) indexing (both of the options are valid as candidates for our date field, of course the date time is more fit if there is no real impact on performance)

Best Answer

In MongoDB dates are stored as BSON Dates and this type is a 64-bit integer that represents the number of milliseconds since the Unix epoch (Jan 1, 1970). This means that dates and date-time values are stored in the same format, so there is no difference in indexing on either of them.