We’re having a discussion about storing dates in a MongoDB. I’m still pretty new to Mongo, so when I see the following in the documentation (http://api.mongodb.org/perl/MongoDB/DataTypes.html#Dates) I wonder:
Warning: creating DateTime objects is
extremely slow. Consider saving dates
as numbers and converting the numbers
to DateTimes when needed. A single
DateTime field can make
deserialization up to 10 times slower.
If we’re just storing them and having them come out with a query on the objects in the store, it’s one thing, but it seems that if we’re filtering or sorting on those fields it’s another. The issue is the casting back and forth from a number to DateTime. Any thoughts on performance considerations are welcome. Thanks.
Internally both datetime and long are stored as 64 bit ints per bsonspec http://bsonspec.org/#/specification. So there not be an additional perf penalty due to the cast from a server perspective. the problem is with the slowness of DateTime in perl.
Note: use datetime or long consistently as one will not match the other.