您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 铜仁分类信息网,免费分类信息发布

MongoDB的聚合查询

2024/3/24 20:56:35发布34次查看
mongodb的聚合查询 java代码 www.2cto.com mongoclient mongoclient = null; try { mongoclient = new mongoclient(102.198.119.29, 27017); db db = mongoclient.getdb(syslog); //设置where条件 dbobject match = new basicdbobject($match, new basicdbob
mongodb的聚合查询
java代码    www.2cto.com  
mongoclient mongoclient = null;  
try {  
    mongoclient = new mongoclient(102.198.119.29, 27017);  
    db db = mongoclient.getdb(syslog);  
    //设置where条件  
    dbobject match = new basicdbobject($match, new basicdbobject(  
            date,  
            (new basicdbobject($gt, 2012-11-28 00:19:00)).append(  
                    $lt, 2012-11-29 09:19:00)));
//设置分组字段  
    basicdbobject groupfilters = new basicdbobject(_id, $priority);  
    //对分组字段统计行数  
    groupfilters.put(count, new basicdbobject($sum, 1));  
    basicdbobject group = new basicdbobject($group, groupfilters);  
    //设置显示的字段集合
dbobject fields = new basicdbobject(priority, 1);  
    fields.put(_id, $priority);  
    dbobject project = new basicdbobject($project, fields);  
    aggregationoutput output = db.getcollection(messages).aggregate(  
            match, project, group);  
    system.out.println(output.getcommandresult());  
} catch (unknownhostexception e) {  
    e.printstacktrace();  
}
铜仁分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录