mongodb的group详细成功案例

/**
	 * 查询财务报表
	 * @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详细成功案例

上一篇:Oracle升级_oracle 10g版本由 10.2.0.4.0升级为10.2.0.4.4(即PSU升级)


下一篇:使用origin 防止csrf *** 以及指定域名访问防盗链