/** * Returns a single object from this collection matching the query. * * @param query the query object * @param fields an object for which every non null field will be returned * @param readPref The read preferences * @return the object found, or <code>null</code> if no such object exists */ public T findOne(T query, T fields, ReadPreference readPref) { DBCursor<T> cursor = find(query, fields).setReadPreference(readPref); if (cursor.hasNext()) { return cursor.next(); } else { return null; } }
/** * Queries for all objects in this collection. * * @return a cursor which will iterate over every object * @throws MongoException If an error occurred */ public final DBCursor<T> find() throws MongoException { return new DBCursor<T>(this, dbCollection.find()); }
/** * Checks if there is another object available * * @return true if there is another object available * @throws MongoException */ public boolean hasNext() throws MongoException { executed(); return cursor.hasNext(); }
@Path("bars") @GET @Produces(MediaType.APPLICATION_JSON) public List<Bar> listBars() { return getJacksonDBCollection().find().toArray(); }
@Override protected DBCursor<T> put(String field, String op, Object value) { checkExecuted(); return super.put(field, op, jacksonDBCollection.serializeField(value)); }
/** * creates a copy of this cursor object that can be iterated. * Note: * - you can iterate the DBCursor itself without calling this method * - no actual data is getting copied. * * @return The iterator */ public Iterator<T> iterator() { return this.copy(); }
/** * Checks if there is another object available * * @return true if there is another object available * @throws MongoException */ public boolean hasNext() throws MongoException { executed(); return cursor.hasNext(); }
@Override protected DBCursor<T> put(String field, String op, Object value) { checkExecuted(); return super.put(field, op, jacksonDBCollection.serializeField(value)); }
/** * creates a copy of this cursor object that can be iterated. * Note: * - you can iterate the DBCursor itself without calling this method * - no actual data is getting copied. * * @return The iterator */ public Iterator<T> iterator() { return this.copy(); }
/** * Returns a single object from this collection matching the query. * * @param query the query object * @param fields fields to return * @param readPref The read preference * @return the object found, or <code>null</code> if no such object exists */ public T findOne(DBObject query, DBObject fields, ReadPreference readPref) { DBCursor<T> cursor = find(query, fields).setReadPreference(readPref); if (cursor.hasNext()) { return cursor.next(); } else { return null; } }
/** * for testing only! * Iterates cursor and counts objects * * @return num objects * @see #count() */ public int itcount() { executed(); return cursor.itcount(); }
/** * Queries for all objects in this collection. * * @return a cursor which will iterate over every object * @throws MongoException If an error occurred */ public final DBCursor<T> find() throws MongoException { return new DBCursor<T>(this, dbCollection.find()); }
@Override protected DBCursor<T> putGroup(String op, Object... expressions) { checkExecuted(); Object[] serialized = new Object[expressions.length]; for (int i = 0; i < expressions.length; i++) { serialized[i] = jacksonDBCollection.serializeField(expressions[i]); } return super.putGroup(op, serialized); } }
/** * Returns a single object from this collection matching the query. * * @param query the query object * @param fields an object for which every non null field will be returned * @param readPref The read preferences * @return the object found, or <code>null</code> if no such object exists */ public T findOne(T query, T fields, ReadPreference readPref) { DBCursor<T> cursor = find(query, fields).setReadPreference(readPref); if (cursor.hasNext()) { return cursor.next(); } else { return null; } }
/** * 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(); }
/** * Creates a copy of an existing database cursor. * The new cursor is an iterator, even if the original * was an array. * * @return the new cursor */ public DBCursor<T> copy() { return new DBCursor<T>(jacksonDBCollection, cursor.copy()); }