我有一个 MongoDB,它以 UTC 存储日期对象。好吧,我想在不同的时区 (CET) 中按年月日执行聚合。
这样做,适用于 UTC:
BasicDBObject group_id = new BasicDBObject("_id", new BasicDBObject("year", new BasicDBObject("$year", "$tDate")).
append("month", new BasicDBObject("$month", "$tDate")).
append("day", new BasicDBObject("$dayOfMonth", "$tDate")).
append("customer", "$customer"));
BasicDBObject groupFields = group_id.
append("eventCnt", new BasicDBObject("$sum", "$eventCnt"));
BasicDBObject group = new BasicDBObject("$group", groupFields);
或者,如果您使用命令行(未测试,我只测试了 java 版本):
{
$group: {
_id: {
"year": {
"$year", "$tDate"
},
"month": {
"$month", "$tDate"
},
"day": {
"$dayOfMonth", "$tDate"
},
"customer": "$customer"
},
"eventCount": {
"$sum": "$eventCount"
}
}
}
如何在聚合框架内将这些日期转换为 CET?
例如“2013-09-16 23:45:00 UTC”是“2013-09-17 00:45:00 CET”,这是不同的一天。