【发布时间】:2014-11-25 14:01:39
【问题描述】:
如何在 mongodb-async-driver (http://www.allanbank.com/mongodb-async-driver/usage.html) 中按小时聚合
我的收藏中有一个 ISODate-Field。
[
{ name = "a", date = ISODate(...)},
{ name = "b", date = ISODate(...)},
...
]
我想显示一个图表,说明每小时可能出现的文档数量。 在 MongoDB 控制台中。我会这样做:
db.mycollection.aggregate([{$group : {_id : {day:{ $hour : "$date"}}, count: { $sum: 1 }}}])
但我卡在驱动程序 api 上:
import static com.allanbank.mongodb.builder.AggregationGroupField.set;
import static com.allanbank.mongodb.builder.AggregationGroupId.id;
Aggregate.Builder builder = new Aggregate.Builder();
builder.group(id().add(???), set("pop").sum("pop"))
【问题讨论】:
标签: java mongodb asynchronous driver