【问题标题】:Aggregate each month in mongodb "exception: can't convert from BSON type EOO to Date"在 mongodb 中每月汇总“异常:无法从 BSON 类型 EOO 转换为日期”
【发布时间】:2014-07-16 02:15:49
【问题描述】:

这是我的文档:

{ "_id" : "ea:site:1000000_cate:-1:date:2014-05-12", 
"dateTime" : ISODate("2014-05-11T17:00:00Z"), 
"site" : 1000000, 
"category" : -1, 
"visit" : 8619007, 
"pageview" : 34190331, 
"timespan" : NumberLong(479), 
"uniqueVisit" : 3581170, 
"pagePerVisit" : 3.9668526780405213, 
"bounceRate" : 48.43801758071321, 
"newVisit" : 12.231621858238226, 
"timeType" : 2 
}

这是我的查询:

db.getCollection("eclick.analytics.1000000.-1").aggregate(
    { "$match" : { "site" : 1000000 , "category" : -1 }}, 
    { "$project" : { "_id" : 1 , 
                     "pageview" : 1 , 
                     "visit" : 1 , 
                     "uniqueVisit" : 1 , 
                     "timespan" : 1 , 
                     "pagePerVisit" : 1 , 
                     "bounceRate" : 1 , 
                     "newVisit" : 1}}, 
    { "$group" : { "_id" : { "$month" : ISODate($dateTime)} , 
                   "pageview" : { "$sum" : "$pageview"} , 
                   "visit" : { "$sum" : "$visit"} , 
                   "uniqueVisit" : { "$sum" : "$uniqueVisit"} , 
                   "timespan" : { "$avg" : "$timespan"} , 
                   "pagePerVisit" : { "$avg" : "$pagePerVisit"} , 
                   "bounceRate" : { "$avg" : "$bounceRate"} , 
                   "newVisit" : { "$avg" : "$newVisit"}}});

--

Tue May 27 15:38:37.660 ReferenceError: $dateTime is not defined

--

db.getCollection("eclick.analytics.1000000.-1").aggregate(
    { "$match" : { "site" : 1000000 , "category" : -1 }}, 
    { "$project" : { "_id" : 1 , 
                     "pageview" : 1 , 
                     "visit" : 1 , 
                     "uniqueVisit" : 1 , 
                     "timespan" : 1 , 
                     "pagePerVisit" : 1 , 
                     "bounceRate" : 1 , 
                     "newVisit" : 1}}, 
    { "$group" : { "_id" : { "$month" : "$dateTime"} , 
                   "pageview" : { "$sum" : "$pageview"} , 
                   "visit" : { "$sum" : "$visit"} , 
                   "uniqueVisit" : { "$sum" : "$uniqueVisit"} , 
                   "timespan" : { "$avg" : "$timespan"} , 
                   "pagePerVisit" : { "$avg" : "$pagePerVisit"} , 
                   "bounceRate" : { "$avg" : "$bounceRate"} , 
                   "newVisit" : { "$avg" : "$newVisit"}}});

--

Error: Printing Stack Trace
    at printStackTrace (src/mongo/shell/utils.js:37:15)
    at DBCollection.aggregate (src/mongo/shell/collection.js:897:9)
    at (shell):1:49
Tue May 27 15:38:44.100 aggregate failed: {
    "errmsg" : "exception: can't convert from BSON type EOO to Date",
    "code" : 16006,
    "ok" : 0
} at src/mongo/shell/collection.js:898

你对这个问题有什么想法吗?谢谢

【问题讨论】:

  • 您是否介意格式化您的 JSON 结构以便正确读取它。

标签: mongodb aggregation-framework


【解决方案1】:

您从projection 中排除了$dateTime 字段,因此在$group 阶段您没有它。

【讨论】:

    猜你喜欢
    • 2017-04-22
    • 2013-04-18
    • 2015-04-09
    • 2017-09-23
    • 2018-05-24
    • 2017-11-04
    • 2017-06-17
    • 2021-03-22
    相关资源
    最近更新 更多