开发者

Store dates in MongoDB as integer rather than MongoDate value

开发者 https://www.devze.com 2023-01-10 10:12 出处:网络
Are there any disadvantages to storing dates as integers (timestamps) in MongoDB rather than its MongoDate format?

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 re开发者_如何学Cad 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消