我想运行聚合查询,它也有查找功能吗?

时间:2017-01-12 08:01:16

标签: mongodb mongodb-query aggregation-framework

我在Mongodb中运行聚合查询

db.Data_Urls.aggregate([{$group : {_id : "$Urls", Done:{$sum:1}}}])

所以结果就像

{ 
    "_id" : "hassan", 
    "Done" : NumberInt(1)
},    
{ 
    "_id" : "ahmed", 
    "Done" : NumberInt(3)
},    
{ 
    "_id" : "naveed", 
    "Done" : NumberInt(1)
},    
{ 
    "_id" : "ali", 
    "Done" : NumberInt(1)
},    
{ 
    "_id" : "haroon", 
    "Done" : NumberInt(2)
}

我想在同一查询中过滤Done值,只获取值为1的Done值?

1 个答案:

答案 0 :(得分:0)

db.Data_Urls.aggregate([
     {$group : {_id : "$Urls", Done:{$sum:1}}},
     {$match : { Done: 1 }}
])