dongren9966 2015-07-28 17:30
浏览 63

当我尝试在mongodb上获取数据时,我遇到了错误

I have many stats data like this:

enter image description here

I have face to get this error when i get this data in controller:

Could not convert array to a date value 

Stacktrace:

    Stack Trace
in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Types/DateType.php at line 67   -
        }
        if ($datetime === false) {
            throw new \InvalidArgumentException(sprintf('Could not convert %s to a date value', is_scalar($value) ? '"'.$value.'"' : gettype($value)), 0, $exception);
        }
        return $datetime;
at DateType ::getDateTime (array('date' => '2014-07-16 13:39:01.000000', 'timezone_type' => '3', 'timezone' => 'Europe/Istanbul')) 
in app/cache/dev/doctrine/odm/mongodb/Hydrators/OjsAnalyticsBundleDocumentObjectViewsHydrator.php at line 81   +
at OjsAnalyticsBundleDocumentObjectViewsHydrator ->hydrate (object(ObjectViews), array('_id' => object(MongoId), 'entity' => 'article', 'objectId' => '116597', 'logDate' => array('date' => '2014-07-16 13:39:01.000000', 'timezone_type' => '3', 'timezone' => 'Europe/Istanbul')), array()) 
in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php at line 453   +
at HydratorFactory ->hydrate (object(ObjectViews), array('_id' => object(MongoId), 'entity' => 'article', 'objectId' => '116597', 'logDate' => array('date' => '2014-07-16 13:39:01.000000', 'timezone_type' => '3', 'timezone' => 'Europe/Istanbul')), array()) 
in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php at line 2843   +
at UnitOfWork ->getOrCreateDocument ('Ojs\AnalyticsBundle\Document\ObjectViews', array('_id' => object(MongoId), 'entity' => 'article', 'objectId' => '116597', 'logDate' => array('date' => '2014-07-16 13:39:01.000000', 'timezone_type' => '3', 'timezone' => 'Europe/Istanbul')), array()) 
in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Cursor.php at line 224   +
at Cursor ->current ()
at iterator_to_array (object(Cursor), false) 
in vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Cursor.php at line 628   +
at Cursor ->Doctrine\MongoDB\{closure} () 
in vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Cursor.php at line 660   +
at Cursor ->retry (object(Closure), true) 
in vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Cursor.php at line 629   +
at Cursor ->toArray (false) 
in vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentRepository.php at line 173   +
at DocumentRepository ->findBy (array('entity' => 'article', 'objectId' => '116597')) 
in src/Ojs/Common/Services/JournalService.php at line 338   +
at JournalService ->getArticleStats ('116597', object(Journal)) 
in src/Ojs/ReportBundle/Controller/AnalyticsReportController.php at line 66   +
at AnalyticsReportController ->detailAction ('116597')
at call_user_func_array (array(object(AnalyticsReportController), 'detailAction'), array('116597')) 
in app/bootstrap.php.cache at line 3094   +
at HttpKernel ->handleRaw (object(Request), '1') 
in app/bootstrap.php.cache at line 3056   +
at HttpKernel ->handle (object(Request), '1', true) 
in app/bootstrap.php.cache at line 3207   +
at ContainerAwareHttpKernel ->handle (object(Request), '1', true) 
in app/bootstrap.php.cache at line 2429   +
at Kernel ->handle (object(Request)) 
in web/app_dev.php at line 31   +

Related field mapping in MongoDB mapping file:

 /**
     * @MongoDB\Date
     */
    public $logDate;
/**
     * Get logDate
     *
     * @return @MongoDb\Date $logDate
     */
    public function getLogDate()
    {
        return $this->logDate;
    }

    /**
     * Set logDate
     *
     * @param  $logDate
     * @return self
     */
    public function setLogDate($logDate)
    {
        $this->logDate = $logDate;

        return $this;
    }

First of all, i ask 2 questions about this things.

  • Why mongodb storing date data as an object/array ?
  • How can i fix this shit ?

thanks for all interests.

  • 写回答

1条回答 默认 最新

  • douti9253 2015-07-28 17:39
    关注

    logDate is an array because it contains the following properties date, timezone_type and timezone. No idea why MongoDB is doing that I have never really worked with it so I do not have an answer to that question. However, if you want to handle timezone information as well you can just format the date into ISO8601 and store that then cross reference the given timezone for the actual name of the timezone.

    To fix the logDate issue you can just use it as an array e.g. logDate['date'] to get the actually date time.

    评论

报告相同问题?

悬赏问题

  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解