yes it does.
The difference is produced on basis that date object is stored as a number in dateTime object.
To understood this we could go with this ilustration:
When there is a query on dateTime
filed and dateTime
is stored in numerical object, that means we have comparison on numbers. Mongo will compare object with size of 64 bits (8bytes) see here with same object.
When comparing string, mongo loads string like this: 2016-06-27T08:39:44.000
which is 23 chars*2bytes (utf) => 46 bytes to compare in memory and need to check all bytes from highest to lowest one..
Now, you know the answer why it is faster using dateObject instead of string.
Any comments welcome!
link here
Comparison/Sort Order
- MinKey (internal type)
- Null
- Numbers (ints, longs, doubles)
- Symbol, String
- Object
- Array
- BinData
- ObjectId
- Boolean
- Date
- Timestamp
- Regular
- Expression
- MaxKey (internal type)