protected List<Object> getIds(Class<?> targetType, Predicate condition) { DBCollection collection = getCollection(targetType); // TODO : fetch only ids DBCursor cursor = createCursor(collection, condition, null, QueryModifiers.EMPTY, Collections.<OrderSpecifier<?>>emptyList()); if (cursor.hasNext()) { List<Object> ids = new ArrayList<Object>(cursor.count()); for (DBObject obj : cursor) { ids.add(obj.get("_id")); } return ids; } else { return Collections.emptyList(); } }
@Override public List<String> typeNames() { DBCursor cursor = collection.find( new BasicDBObject(), new BasicDBObject(FeatureTypeDBObject.KEY_typeName, 1)); List<String> typeNames = new ArrayList<String>(cursor.count()); while (cursor.hasNext()) { DBObject document = cursor.next(); if (document != null) { Object typeName = document.get(FeatureTypeDBObject.KEY_typeName); if (typeName instanceof String) { typeNames.add((String) typeName); } } } return typeNames; }
@Override public int count() { return cursor.count(); }
@Override public int count() { return cursor.count(); }
DBCursor cursor = collection.find(query).limit(batchSize); logger.info("{} items found.", cursor.count()); while (cursor.hasNext()) { ... }
/** * Counts the number of objects matching the query This does not take * limit/skip into consideration * * @return the number of objects * @throws MongoException * @see #size() */ public int count() { executed(); return cursor.count(); }
/** * Counts the number of objects matching the query * This does not take limit/skip into consideration * * @return the number of objects * @throws MongoException * @see #size() */ public int count() { executed(); return cursor.count(); }
/** * Counts the number of objects matching the query * This does not take limit/skip into consideration * * @return the number of objects * @throws MongoException * @see #size() */ public int count() { executed(); return cursor.count(); }
@Override public long readCount(Query<?> query) { return find(query).count(); }
MongoClient client = new MongoClient(MONGOHOST,MONGOPORT); DBCollection coll = client.getDB(DBNAME).getCollection(COLLECTION); DBObject query = new Querybuilder().start() .put("_id").lessThan(100).get(); DBCursor result = coll.find(query); System.out.println("Number of pictures found: " + result.count() );
@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); } } return outputsCountByType; }
public boolean removeCalendar(String calName) throws JobPersistenceException { BasicDBObject searchObj = new BasicDBObject(CALENDAR_NAME, calName); if (calendarCollection.find(searchObj).count() > 0) { calendarCollection.remove(searchObj); return true; } return false; }
DBCollection coll = db.getCollection("minnalPolicyMetadata"); BasicDBObject searchDocument = new BasicDBObject(); searchDocument.put("policyMap.CostCalculation",new BasicDBObject("$exists",true)); DBCursor cursor = coll.find(searchDocument); if(cursor.count() != 0){ while(cursor.hasNext()) System.out.println(cursor.next()); }
public boolean checkExists(JobKey jobKey) throws JobPersistenceException { return jobCollection.find(keyAsDBObject(jobKey)).count() > 0; }
/** * Constructor of a page result with a {@link DBCursor} which paginate this * cursor by using limit(), skip() strategy. * * @param cursor * the cursor to paginate. * @param fromItemIndex * the from item index of the page. * @param toItemIndex * the to item index of the page. */ public PageResult(DBCursor cursor, int fromItemIndex, int toItemIndex) { this(cursor.skip(fromItemIndex).limit(toItemIndex - fromItemIndex + 1), fromItemIndex, toItemIndex, cursor.count()); }
BasicDBObject keys = new BasicDBObject(); // will specify the returned fields (SELECT) keys.put("symbol", 1 ); keys.put("price", 1 ); keys.put("Exchange", 1); BasicDBObject query = new BasicDBObject(); // will select the documents you want (WHERE) query.put("numShares", new BasicDBObject("$gte", 0) ); DBCursor cursor_02 = coll_tmp.find( query, keys ); System.out.println( "<2> " + cursor_02.count()); while(cursor_02.hasNext()) { System.out.println( "<2> " + cursor_02.next()); }
public boolean removeTrigger(TriggerKey triggerKey) throws JobPersistenceException { BasicDBObject dbObject = keyAsDBObject(triggerKey); DBCursor find = triggerCollection.find(dbObject); if (find.count() > 0) { triggerCollection.remove(dbObject); return true; } return false; }
@Override public boolean containsStatement(final RyaStatement statement) throws ContainsStatementException { final DBObject dbo = adapter.serialize(statement); return db.getCollection(TRIPLES_COLLECTION).find(dbo).count() > 0; }
public int count() { return collection().find(translateMapToDBObject(selector)).count(); }
@Override @SuppressWarnings("unchecked") public <T> PaginatedResult<T> readPartial(Query<T> query, long offset, int limit) { List<T> list = new ArrayList<T>(); DBCursor cursor = find(query).skip((int) offset).limit(limit); for (DBObject item : cursor) { list.add((T) loadObject(item.toMap())); } return new PaginatedResult<T>(offset, limit, cursor.count(), list); }