MongoDB的ISODate()与UNIX时间戳 [英] MongoDB's ISODate() vs. UNIX Timestamp

查看:309
本文介绍了MongoDB的ISODate()与UNIX时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将日期以ISODate()的形式存储在MongoDB中与以常规UNIX时间戳的形式存储中相比,是否具有某种优势(性能,索引,大小等)?

Is there any sort of advantage (performance, indexes, size, etc) to storing dates in MongoDB as an ISODate() vs. storing as a regular UNIX timestamp?

推荐答案

ISODate与time_t的开销相比,前者的优势微不足道.

The amount of overhead of a ISODate compared to a time_t is trivial compared to the advantages of the former.

ISO 8601格式的日期是人类可读的,可以用来表示1970年1月1日之前的日期,最重要的是,它不是

An ISO 8601 format date is human readable, it can be used to express dates prior to January 1, 1970, and most importantly, it isn't prey to the Y2038 problem.

这最后一点强调得不够.在1960年,在一个世纪数字上浪费一两个八位字节可能会产生任何好处,因为世纪之交不可能遥遥无期.我们知道原来是错误的. 2038年将比您预期的要早,并且time_t已经不足以表示例如30年合同的付款时间表.

This last bit can't be stressed enough. In 1960, it seemed ludicrous that wasting an octet or two on a century number could yield any benefit as the turn of the century was impossibly far off. We know how wrong that turned out to be. The year 2038 will be here sooner than you expect, and time_t are already insufficient for representing – for example – the schedule of payments on a 30-year contract.

这篇关于MongoDB的ISODate()与UNIX时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆