在MongoDB中存储DateTime对性能有影响 [英] Storing DateTime in MongoDB effects on performance

查看:246
本文介绍了在MongoDB中存储DateTime对性能有影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在讨论在MongoDB中存储日期。我对Mongo还是很新的,所以当我在文档(http://api.mongodb.org/perl/MongoDB/DataTypes.html#Dates)中看到以下内容时,我想知道:

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:


警告:创建DateTime对象是
非常慢。考虑将日期
保存为数字,并在需要时将数字
转换为DateTimes。单个
DateTime字段可以使
反序列化速度降低10倍。

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.

如果我们只是存储他们让他们对商店中的对象进行查询,这是一回事,但似乎如果我们在这些字段上进行过滤或排序,那是另一回事。问题是从一个数字到DateTime来回转换。欢迎对性能考虑的任何想法。谢谢。

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.

推荐答案

内部的datetime和long都存储为64位ints每个bsonspec http://bsonspec.org/#/specification 。因此,从服务器角度来看,没有额外的罚款。问题在于Perl中DateTime的缓慢。
注意:使用datetime或长时间一致,因为一个不匹配另一个。

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.

这篇关于在MongoDB中存储DateTime对性能有影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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