views:

69

answers:

1

Are there any disadvantages to storing dates as integers (timestamps) in MongoDB rather than its MongoDate format?

Because I'm having problems with Zend Framework and Doctrine ODM to read the data, since I get them returned as an array as DateTime object. Internally MongoDB seems to save them as Timestamps, but has its own object for it.

A: 

MongoDB uses its own object type MongoDate, which resembles an integer timestamp.

When using Doctrine ODM, this value is converted into a DateTime PHP object.

You can create a custom Date type with Doctrine, that transforms the MongoDate object into a Zend_Date object:

Doctrine\ODM\MongoDB\Mapping\Types\Type::overrideType("date", "My_Date_Class");

That way you skip the DateTime object on the PHP side, but store correct Date objects that MongoDB can understand.

Sebastian Hoitz