principleMinor
Indexing a date field on MongoDB - best practice
Viewed 0 times
fieldindexingpracticemongodbdatebest
Problem
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)
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)
Solution
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.
Context
StackExchange Database Administrators Q#123062, answer score: 7
Revisions (0)
No revisions yet.