在mongodb中每月汇总“例外:无法从BSON类型EOO转换为日期”

时间:2014-05-27 08:43:49

标签: mongodb aggregation-framework

这是我的文件:

{ "_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

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

1 个答案:

答案 0 :(得分:2)

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