2014-09-22 42 views
-1

我需要从我的MongoDB数据库中获取信息,但我不能实现与我的实际技能的请求......MongoDB的获取信息,使一些统计

你能不能帮我做吗?

我得: - 对象属性的总和{isDone:真正} - 过滤器由两个日期 - 按月组有关

感谢提前

+0

对不起,我不明白你在问什么。我已经提供了你提到的日期范围。你提供的命令有一个语法错误。领域首先,而不是价值。 – yaoxing 2014-09-26 03:25:28

回答

1

所有你需要的是aggregation framework

db.coll_name.aggregate([ 
    {$match: {date_field: {$gt: new Date("...")}, date_field: {$lt: new Date("...")}}, // date range 
    {$project: {isDone: "$isDone", year: {$year: "$year"}, month: {$month: "$month"}}}, // extract year/month and isDone 
    {$group: {_id: {year: "$year", month: "$month"}, count: {$sum: 1}} 
]);