本文介绍了Nanoseconds从MongoDB ISODate对象丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从MongoDb接口为ISODate对象丢失了纳秒。当我在perl中读取它们时,所有的纳秒设置为零。



首先,我的环境:

  MongoDB版本:1.8.2 
perl v5.12.4
MongoDB perl模块版本:0.701.4

I具有将rtcTime编码为ISODate的Mongo数据库,如下所示:

 rtcTime:ISODate(2013-05- 13T18:54:55.918Z)

提取rtcTime的代码看起来像这样: p>

  my @results = $ db-> get_collection('timings') - > find() - > all(); 
foreach我的$记录(@results)
{
print $ record-> {rtcTime} - > nanoseconds()。\\\
;
}

输出全为0。



要完全重现此问题,请在MongoDB数据库中创建具有任意(非零)hires_epoch值的ISODate对象。然后尝试使用MongoDB / DateTime / DateTime :: Format :: ISO8061模块来提取任何类型的雇用时间数据。



问:为什么我不能从MongoDB ISODate数据获取我的毫秒,微秒或纳秒?

解决方案

这是MongoDB Perl驱动程序与DateTime交互的一个错误。当从数据库检索到ISODate值时,驱动程序 DateTime对象使用其构造函数。但是纳秒部分不会传递给构造函数。



DateTime确实支持传递包括纳秒的完整值,并且应该更新驱动程序来修复。



我为这个错误创建了一个,我将修复它。但也许直到假日周末之后。 :)


I'm losing the nanoseconds from the MongoDb interface for the ISODate object. All the nanoseconds are set to zero when I read them in perl.

First, my environment:

MongoDB version: 1.8.2
perl v5.12.4
MongoDB perl module version: 0.701.4

I have a Mongo DB that has rtcTime coded as an ISODate, as follows:

"rtcTime" : ISODate("2013-05-13T18:54:55.918Z")

The code to extract the rtcTime looks something like this:

my @results = $db->get_collection( 'timings' )->find( )->all();
foreach my $record ( @results )
{
    print $record->{rtcTime}->nanoseconds()."\n";
}

Output is all 0's.

To fully reproduce the problem, create an ISODate object with arbitrary (non-zero) hires_epoch values in the MongoDB database. Then try to use the MongoDB / DateTime / DateTime::Format::ISO8061 modules to extract any kind of hires time data.

Q: Why can't I get my milliseconds, microseconds, or nanoseconds from the MongoDB ISODate data?

解决方案

This is a bug in the way that the MongoDB Perl driver interacts with DateTime. When ISODate values are retrieved from the database, the driver initializes the DateTime object using its from_epoch constructor. But the nanosecond portion is not passed to the constructor.

DateTime does support passing the full value including nanoseconds, and the driver should be updated to fix that.

I've created a ticket for this bug and I will fix it. But maybe not until after the holiday weekend. :)

这篇关于Nanoseconds从MongoDB ISODate对象丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 11:57