/** * find distinct values for a key * * @param key The key * @param query query to match * @return The results */ public List distinct(String key, DBObject query) { return dbCollection.distinct(key, serializeFields(query)); }
/** * find distinct values for a key * * @param key The key * @param query query to match * @return The results */ public List distinct(String key, DBObject query) { return dbCollection.distinct(key, serializeFields(query)); }
/** * Returns the number of documents in the collection * that match the specified query * * @param query query to select documents to count * @param fields fields to return * @param limit limit the count to this value * @param skip number of entries to skip * @return number of documents that match query and fields * @throws MongoException If an error occurred */ public long getCount(DBObject query, DBObject fields, long limit, long skip) throws MongoException { return dbCollection.getCount(serializeFields(query), fields, limit, skip); }
/** * Returns the number of documents in the collection * that match the specified query * * @param query query to select documents to count * @param fields fields to return * @param limit limit the count to this value * @param skip number of entries to skip * @return number of documents that match query and fields * @throws MongoException If an error occurred */ public long getCount(DBObject query, DBObject fields, long limit, long skip) throws MongoException { return dbCollection.getCount(serializeFields(query), fields, limit, skip); }
/** * performs a map reduce operation * Runs the command in REPLACE output mode (saves to named collection) * * @param map map function in javascript code * @param outputTarget optional - leave null if want to use temp collection * @param reduce reduce function in javascript code * @param query to match * @return The output * @throws MongoException If an error occurred */ @Deprecated public com.mongodb.MapReduceOutput mapReduce(String map, String reduce, String outputTarget, DBObject query) throws MongoException { return mapReduce(new MapReduceCommand(dbCollection, map, reduce, outputTarget, MapReduceCommand.OutputType.REPLACE, serializeFields(query))); }
/** * performs a map reduce operation * Runs the command in REPLACE output mode (saves to named collection) * * @param map map function in javascript code * @param outputTarget optional - leave null if want to use temp collection * @param reduce reduce function in javascript code * @param query to match * @return The output * @throws MongoException If an error occurred */ @Deprecated public com.mongodb.MapReduceOutput mapReduce(String map, String reduce, String outputTarget, DBObject query) throws MongoException { return mapReduce(new MapReduceCommand(dbCollection, map, reduce, outputTarget, MapReduceCommand.OutputType.REPLACE, serializeFields(query))); }
/** * Removes objects from the database collection. * * @param query the object that documents to be removed must match * @param concern WriteConcern for this operation * @return The result * @throws MongoException If an error occurred */ public WriteResult<T, K> remove(DBObject query, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(serializeFields(query), concern)); }
/** * Queries for an object in this collection. * * @param query object for which to search * @return an iterator over the results * @throws MongoException If an error occurred */ public DBCursor<T> find(DBObject query) throws MongoException { return new DBCursor<T>(this, dbCollection.find(serializeFields(query))); }
/** * calls {@link DBCollection#remove(com.mongodb.DBObject, com.mongodb.WriteConcern)} with the default WriteConcern * * @param query the query that documents to be removed must match * @return The write result * @throws MongoException If an error occurred */ public WriteResult<T, K> remove(DBObject query) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(serializeFields(query))); }
/** * calls {@link DBCollection#remove(com.mongodb.DBObject, com.mongodb.WriteConcern)} with the default WriteConcern * * @param query the query that documents to be removed must match * @return The write result * @throws MongoException If an error occurred */ public WriteResult<T, K> remove(DBObject query) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(serializeFields(query))); }
/** * Removes objects from the database collection. * * @param query the object that documents to be removed must match * @param concern WriteConcern for this operation * @return The result * @throws MongoException If an error occurred */ public WriteResult<T, K> remove(DBObject query, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(serializeFields(query), concern)); }
/** * Queries for an object in this collection. * * @param query object for which to search * @return an iterator over the results * @throws MongoException If an error occurred */ public DBCursor<T> find(DBObject query) throws MongoException { return new DBCursor<T>(this, dbCollection.find(serializeFields(query))); }
/** * Finds the first document in the query and updates it. * * @param query query to match * @param fields fields to be returned * @param sort sort to apply before picking first document * @param remove if true, document found will be removed * @param update update to apply * @param returnNew if true, the updated document is returned, otherwise the old document is returned (or it would be lost forever) * @param upsert do upsert (insert if document not present) * @return the object */ public T findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify(serializeFields(query), fields, sort, remove, update, returnNew, upsert)); }
/** * Finds the first document in the query and updates it. * * @param query query to match * @param fields fields to be returned * @param sort sort to apply before picking first document * @param remove if true, document found will be removed * @param update update to apply * @param returnNew if true, the updated document is returned, otherwise the old document is returned (or it would be lost forever) * @param upsert do upsert (insert if document not present) * @return the object */ public T findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify(serializeFields(query), fields, sort, remove, update, returnNew, upsert)); }
/** * performs a map reduce operation * Specify an outputType to control job execution * * INLINE - Return results inline * * REPLACE - Replace the output collection with the job output * * MERGE - Merge the job output with the existing contents of outputTarget * * REDUCE - Reduce the job output with the existing contents of * outputTarget * * @param map map function in javascript code * @param outputTarget optional - leave null if want to use temp collection * @param outputType set the type of job output * @param reduce reduce function in javascript code * @param query to match * @return The output * @throws MongoException If an error occurred */ @Deprecated public com.mongodb.MapReduceOutput mapReduce(String map, String reduce, String outputTarget, MapReduceCommand.OutputType outputType, DBObject query) throws MongoException { return mapReduce(new MapReduceCommand(dbCollection, map, reduce, outputTarget, outputType, serializeFields(query))); }
/** * Performs an update operation. * * @param query search query for old object to update * @param object object with which to update <tt>query</tt> * @param upsert if the database should create the element if it does not exist * @param multi if the update should be applied to all objects matching (db version 1.1.3 and above). An object will * not be inserted if it does not exist in the collection and upsert=true and multi=true. * See <a href="http://www.mongodb.org/display/DOCS/Atomic+Operations">http://www.mongodb.org/display/DOCS/Atomic+Operations</a> * @param concern the write concern * @return The write result * @throws MongoException If an error occurred */ public WriteResult<T, K> update(DBObject query, DBObject object, boolean upsert, boolean multi, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.update(serializeFields(query), object, upsert, multi, concern)); }
/** * Performs an update operation. * * @param query search query for old object to update * @param object object with which to update <tt>query</tt> * @param upsert if the database should create the element if it does not exist * @param multi if the update should be applied to all objects matching (db version 1.1.3 and above). An object will * not be inserted if it does not exist in the collection and upsert=true and multi=true. * See <a href="http://www.mongodb.org/display/DOCS/Atomic+Operations">http://www.mongodb.org/display/DOCS/Atomic+Operations</a> * @param concern the write concern * @return The write result * @throws MongoException If an error occurred */ public WriteResult<T, K> update(DBObject query, DBObject object, boolean upsert, boolean multi, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.update(serializeFields(query), object, upsert, multi, concern)); }
/** * performs a map reduce operation * Specify an outputType to control job execution * * INLINE - Return results inline * * REPLACE - Replace the output collection with the job output * * MERGE - Merge the job output with the existing contents of outputTarget * * REDUCE - Reduce the job output with the existing contents of * outputTarget * * @param map map function in javascript code * @param outputTarget optional - leave null if want to use temp collection * @param outputType set the type of job output * @param reduce reduce function in javascript code * @param query to match * @return The output * @throws MongoException If an error occurred */ @Deprecated public com.mongodb.MapReduceOutput mapReduce(String map, String reduce, String outputTarget, MapReduceCommand.OutputType outputType, DBObject query) throws MongoException { return mapReduce(new MapReduceCommand(dbCollection, map, reduce, outputTarget, outputType, serializeFields(query))); }
/** * Queries for an object in this collection. * <p/> * <p> * An empty DBObject will match every document in the collection. * Regardless of fields specified, the _id fields are always returned. * </p> * <p> * An example that returns the "x" and "_id" fields for every document * in the collection that has an "x" field: * </p> * <blockquote><pre> * BasicDBObject keys = new BasicDBObject(); * keys.put("x", 1); * <p/> * DBCursor cursor = collection.find(new BasicDBObject(), keys); * </pre></blockquote> * * @param query object for which to search * @param keys fields to return * @return a cursor to iterate over results */ public final DBCursor<T> find(DBObject query, DBObject keys) { return new DBCursor<T>(this, dbCollection.find(serializeFields(query), keys)); }
/** * Finds the first document in the query and updates it. * * @param query query to match * @param fields fields to be returned * @param sort sort to apply before picking first document * @param remove if true, document found will be removed * @param update update to apply * @param returnNew if true, the updated document is returned, otherwise the old document is returned (or it would be lost forever) * @param upsert do upsert (insert if document not present) * @return the object */ public T findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBUpdate.Builder update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify(serializeFields(query), fields, sort, remove, update.serialiseAndGet(objectMapper), returnNew, upsert)); }