List of usage examples for com.mongodb DBCollection group
@Deprecated public DBObject group(final DBObject key, final DBObject cond, final DBObject initial, final String reduce)
From source file:mongodb.javaGroup.java
public static void firstIsALastIsVowel(DBCollection collection) { BasicDBObject key = new BasicDBObject("first", true); key.append("last", true); BasicDBObject cond = new BasicDBObject("first", "a"); cond.append("last", new BasicDBObject("$in", new String[] { "a", "e", "i", "o", "u" })); BasicDBObject initial = new BasicDBObject("count", 0); String reduce = "function (obj, prev) { prev.count++; }"; DBObject result = collection.group(key, cond, initial, reduce); System.out.println("\n'A' words grouped by first and last" + " letter that end with a vowel"); javaGroup.displayGroup(result);/*from w ww. j a va2 s .c o m*/ }
From source file:net.cit.tetrad.rrd.dao.MongoStatusToMonitorImpl.java
License:Open Source License
public List<Object> readMongoChunksGrp(Mongo mongo, String collName, List<Object> dboLst) throws MongoException, Exception { try {/*from w w w. j av a 2 s.c om*/ DB db = mongo.getDB("config"); DBCollection dbcollection = db.getCollectionFromString("chunks"); DBObject dbo = dbcollection.group(new BasicDBObject("shard", true), new BasicDBObject("ns", collName), new BasicDBObject("nChunks", 0), "function (doc, out) {out.nChunks++;}"); Iterator<String> keys = dbo.keySet().iterator(); BasicDBObject getDbo; while (keys.hasNext()) { String key = keys.next(); getDbo = (BasicDBObject) dbo.get(key); getDbo.put("collName", collName); dboLst.add(getDbo); } } catch (DataAccessResourceFailureException e) { e.printStackTrace(); throw new MongoException(e.getMessage()); } catch (MongoException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } finally { } return dboLst; }