首页 > 数据库技术 > 详细

mongodb的group详细成功案例

时间:2014-08-12 19:06:14      阅读:382      评论:0      收藏:0      [点我收藏+]
/**
	 * 查询财务报表
	 * @author liupeng
	 * @param timeStart
	 * @param timeEnd
	 * @return
	 */
	//public List<KeyRequest> findByTimeForFinal(String timeStart, String timeEnd) {
	public List<DBObject> findByTimeForFinal(String timeStart, String timeEnd) {
		
		BasicDBObject key = new BasicDBObject();
		key.put("kq_timer_start", true);   //groupBy的条件
		BasicDBObject cond = new BasicDBObject("kq_timer_start",new BasicDBObject("$gte",timeStart).append("$lt", timeEnd));//查询where条件
		BasicDBObject initial = new BasicDBObject();
		initial.put("cou",0);              //需要查询出来的内容
		initial.put("kq_autosum", "");     //需要查询出来的内容
		initial.put("kq_accountsum", "");  //需要查询出来的内容
		String reduce = "function(obj,out){" +
				"out.cou++;" +
				"out.kq_autosum = out.kq_autosum+obj.kq_autosum+'_';" +
				"out.kq_accountsum = out.kq_accountsum+obj.kq_accountsum+'_';}";
		BasicDBList returnList = (BasicDBList)keyRequest.group(key, cond, initial, reduce);
		System.out.println(returnList);
		List<DBObject> list = new ArrayList<DBObject>();
		Object[] o = returnList.toArray();
		for (int i = 0; i < o.length; i++) {
			DBObject dbObject = (DBObject)o[i];
			list.add(dbObject);
		}
		return list;
		
		//通过以下形式可以打印出BasicDBList中的任何值
		/*
		System.out.println(returnList);
		Object[] o = returnList.toArray();
		for (int i = 0; i < o.length; i++) {
			DBObject dbObject = (DBObject)o[i];
			System.out.println(dbObject.get("kq_id"));
		}
		*/
		
		
	}
	

mongodb的group详细成功案例,布布扣,bubuko.com

mongodb的group详细成功案例

原文:http://blog.csdn.net/liupeng_family/article/details/38518429

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!