81,092
社区成员
发帖
与我相关
我的任务
分享
db.runCommand(
{ group :
{
ns: "Incident" ,
cond : { "$and" : [ { "source" : "外点机房动环"}]} ,
$reduce : function Reduce(doc, out) {
if(doc._id){
out.count +=1;
}
} ,
initial : { "count" : 0} ,
$keyf : function(doc){
var date = new Date(doc.lastOccurTime);
var dateKey = '' + date.getFullYear()+ '-' + (date.getMonth()+1) + '-' + date.getDate() ;
return {'day':dateKey};
}
}
}
)
db.getCollection('Incident').group({
keyf:function(doc){
var date = new Date(doc.lastOccurTime);
var dateKey = '' + date.getFullYear()+ '-' + (date.getMonth()+1) + '-' + date.getDate() ;
return {'day':dateKey}},
cond:{ "$and" : [ { "source" : "外点机房动环"}]},
initial:{"count":0},
reduce:function Reduce(doc, out) {
if(doc._id){
out.count +=1;
}}
})
criteria.andOperator(Criteria.where("source").is("外点机房动环"));
Query query = Query.query(criteria);
BasicDBObject initial = new BasicDBObject();
initial.put("count", 0);
String reduce = "function Reduce(doc, out) { "
+ " if(doc._id){ "
+ " out.count +=1; "
+ " } "
+ " }";
String keyf = "function(doc){ "
+ " var date = new Date(doc.lastOccurTime); "
+ " var dateKey = '' + date.getFullYear()+ '-' + (date.getMonth()+1) + '-' + date.getDate() ; "
+ " return {'day':dateKey}; "
+ " }";
DBCollection collection = mongoTemplate.getCollection("Incident");
GroupCommand Gc = new GroupCommand(collection, keyf, query.getQueryObject(), initial, reduce, null);
logger.debug("GC:" + Gc.toDBObject().toString());
DBObject object = mongoTemplate.getCollection("Incident").group(Gc);
logger.debug("result:" + object.toString());