List of usage examples for com.mongodb DBCursor count
public int count()
From source file:org.benjp.services.mongodb.NotificationServiceImpl.java
License:Open Source License
public int getNumberOfUnreadNotifications() { DBCollection coll = db().getCollection(M_NOTIFICATIONS); BasicDBObject query = new BasicDBObject(); // query.put("isRead", false); DBCursor cursor = coll.find(query); return cursor.count(); }
From source file:org.benjp.services.mongodb.UserServiceImpl.java
License:Open Source License
public int getNumberOfUsers() { DBCollection coll = db().getCollection(M_USERS_COLLECTION); BasicDBObject query = new BasicDBObject(); DBCursor cursor = coll.find(query); return cursor.count(); }
From source file:org.exoplatform.chat.services.mongodb.ChatServiceImpl.java
License:Open Source License
public int getNumberOfMessages() { int nb = 0;/*ww w . ja v a 2 s . c om*/ DBCollection coll = db().getCollection(M_ROOM_PREFIX + M_ROOMS_COLLECTION); BasicDBObject query = new BasicDBObject(); DBCursor cursor = coll.find(query); while (cursor.hasNext()) { DBObject dbo = cursor.next(); String roomId = dbo.get("_id").toString(); DBCollection collr = db().getCollection(M_ROOM_PREFIX + roomId); BasicDBObject queryr = new BasicDBObject(); DBCursor cursorr = collr.find(queryr); // LOG.info(roomId+" = "+cursorr.count()); nb += cursorr.count(); } return nb; }
From source file:org.geotools.data.mongodb.MongoResultSet.java
License:LGPL
/** * Build features for given layer; convert mongo collection records to equivalent geoTools * SimpleFeatureBuilder//ww w . j av a 2 s . c o m * * @param query mongoDB query (empty to find all) */ private void buildFeatures(BasicDBObject query) { if (layer == null) { log.warning("buildFeatures called, but layer is null"); return; } Mongo mongo = null; try { if (layer.getGeometryType() == null) { return; } mongo = new Mongo(layer.getConfig().getHost(), layer.getConfig().getPort()); DB db = mongo.getDB(layer.getConfig().getDB()); DBCollection coll = db.getCollection(layer.getName()); DBCursor cur = coll.find(query); minX = 180; maxX = -180; minY = 90; maxY = -90; SimpleFeatureBuilder fb = new SimpleFeatureBuilder(layer.getSchema()); // use SimpleFeatureBuilder.set(name, value) rather than add(value) since // attributes not in guaranteed order log.finer("cur.count()=" + cur.count()); while (cur.hasNext()) { DBObject dbo = cur.next(); if (dbo == null) { continue; } // get mongo id and ensure valid if (dbo.get("_id") instanceof ObjectId) { ObjectId oid = (ObjectId) dbo.get("_id"); fb.set("_id", oid.toString()); } else if (dbo.get("_id") instanceof String) { fb.set("_id", dbo.get("_id")); } else { throw new MongoPluginException("_id is invalid type: " + dbo.get("_id").getClass()); } // ensure geometry defined DBObject geo = (DBObject) dbo.get("geometry"); if (geo == null || geo.get("type") == null || (geo.get("coordinates") == null && geo.get("geometries") == null)) { continue; } // GeometryType of current record GeometryType recordGeoType = GeometryType.valueOf((String) geo.get("type")); // skip record if its geo type does not match layer geo type if (!layer.getGeometryType().equals(recordGeoType)) { continue; } // create Geometry for given type Geometry recordGeometry = createGeometry(recordGeoType, geo); if (recordGeometry != null) { fb.set("geometry", recordGeometry); // set non-geometry properties for feature (GeoJSON.properties) DBObject props = (DBObject) dbo.get("properties"); setProperties(fb, "properties", props); features.add(fb.buildFeature(null)); bounds = new ReferencedEnvelope(minX, maxX, minY, maxY, layer.getCRS()); } else { fb.reset(); } } } catch (Throwable t) { log.severe("Error building layer " + layer.getName() + "; " + t.getLocalizedMessage()); } if (mongo != null) { mongo.close(); } }
From source file:org.graylog2.inputs.InputServiceImpl.java
License:Open Source License
@Override public Map<String, Long> totalCountByType() { final DBCursor inputTypes = collection(InputImpl.class).find(null, new BasicDBObject(MessageInput.FIELD_TYPE, 1)); final Map<String, Long> inputCountByType = new HashMap<>(inputTypes.count()); for (DBObject inputType : inputTypes) { final String type = (String) inputType.get(MessageInput.FIELD_TYPE); if (type != null) { final Long oldValue = inputCountByType.get(type); final Long newValue = (oldValue == null) ? 1 : oldValue + 1; inputCountByType.put(type, newValue); }/*from w ww. j a v a 2 s . com*/ } return inputCountByType; }
From source file:org.graylog2.streams.OutputServiceImpl.java
License:Open Source License
@Override public Map<String, Long> countByType() { final DBCursor outputTypes = collection(OutputImpl.class).find(null, new BasicDBObject(OutputImpl.FIELD_TYPE, 1)); final Map<String, Long> outputsCountByType = new HashMap<>(outputTypes.count()); for (DBObject outputType : outputTypes) { final String type = (String) outputType.get(OutputImpl.FIELD_TYPE); if (type != null) { final Long oldValue = outputsCountByType.get(type); final Long newValue = (oldValue == null) ? 1 : oldValue + 1; outputsCountByType.put(type, newValue); }//w w w . j ava 2 s . c o m } return outputsCountByType; }
From source file:org.graylog2.streams.OutputServiceMJImpl.java
License:Open Source License
@Override public Map<String, Long> countByType() { final DBCursor outputTypes = dbCollection.find(null, new BasicDBObject(OutputImpl.FIELD_TYPE, 1)); final Map<String, Long> outputsCountByType = new HashMap<>(outputTypes.count()); for (DBObject outputType : outputTypes) { final String type = (String) outputType.get(OutputImpl.FIELD_TYPE); if (type != null) { final Long oldValue = outputsCountByType.get(type); final Long newValue = (oldValue == null) ? 1 : oldValue + 1; outputsCountByType.put(type, newValue); }// w w w . j av a 2s . c o m } return outputsCountByType; }
From source file:org.infinispan.loaders.mongodb.MongoDBCacheStore.java
License:Open Source License
@Override public Set<InternalCacheEntry> loadAll() throws CacheLoaderException { DBCursor dbObjects = this.collection.find(); Set<InternalCacheEntry> entries = new HashSet<InternalCacheEntry>(dbObjects.count()); while (dbObjects.hasNext()) { DBObject next = dbObjects.next(); InternalCacheEntry ice = this.createInternalCacheEntry(next); entries.add(ice);/*from ww w. ja v a 2 s .co m*/ } return entries; }
From source file:org.iternine.jeppetto.dao.mongodb.projections.CountDistinctMapReduceCommand.java
License:Apache License
@Override protected Integer transformToValue(DBCursor dbCursor) { return dbCursor.count(); }
From source file:org.jwebsocket.util.MongoDBConnectorsPacketQueue.java
License:Apache License
@Override public List<String> dequeue(String aConnectorId) throws Exception { DBCursor lCursor = mPackets.find(new BasicDBObject().append("c", aConnectorId)) .sort(new BasicDBObject().append("_id", 1)); List<String> lList = new ArrayList<String>(lCursor.count()); while (lCursor.hasNext()) { lList.add((String) lCursor.next().get("p")); }//from w ww .j ava 2s . c o m mPackets.remove(new BasicDBObject().append("c", aConnectorId)); return lList; }