本文介绍了MongoDB:不能从BSON类型EOO转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用聚合框架(使用ruby),并像这样投影日期:
I' trying to use aggregation framework (with ruby) and project the date like this:
db['requests'].aggregate([
{"$project" => {
_id: 0,
method: '$method',
user: '$user',
year: {'$year' => '$timestamp'}
}}])
$ b b
文件类似这样:
the document is like this one:
{
_id: ObjectId("5177d7d7df26358289da7dfd"),
timestamp: ISODate("2013-04-12T03:58:05+00:00"),
method: "POST",
status: "200",
inputsize: "874",
outputsize: "4981",
user: "131"
}
但我得到以下错误:
Mongo::OperationFailure: Database command 'aggregate' failed: (errmsg: 'exception: can't convert from BSON type EOO to Date'; code: '16006'; ok: '0.0').
这很奇怪,因为它运行正确,如果我运行这个完全相同的数据库导入mongorestore 。
This is strange because it works correctly if I run this on the exactly same db which is imported with mongorestore.
推荐答案
问题是我保存了一些没有时间戳字段的文档。
The problem was that I was saving some documents without the timestamp field.
这篇关于MongoDB:不能从BSON类型EOO转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!