1、distinct操作
db.runCommand({"distinct":"test", "key":"age"})
2、聚合操作
db.doctors.group({
key:{hospital:true},
initial:{count:0},
reduce:function(obj,prev){prev.count++},
})
3、修改键实例
> db.test.group( {
... key: { day: true},
... initial: {count: 0},
... reduce: function(obj,prev){ prev.count++;},
... finalize: function(out){ out.scaledCount = out.count * 10 } --在结果文档中新增一个键。
... } )
结果:
[
{
"day" : "2012-08-20",
"count" : 2,
"scaledCount" : 20
},
{
"day" : "2012-08-21",
"count" : 2,
"scaledCount" : 20
},
{
"day" : "2012-08-22",
"count" : 1,
"scaledCount" : 10
}
]