/** * Find an object by the given id * * @param id * The id * @return The object * @throws MongoException * If an error occurred */ public T findOneById(K id, T fields) throws MongoException { return findOneById(id, convertToBasicDbObject(fields)); }
/** * 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, T update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify( serializeFields(query), fields, sort, remove, convertToBasicDbObject(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(DBQuery.Query query, DBObject fields, DBObject sort, boolean remove, T update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify( serializeQuery(query), fields, sort, remove, convertToBasicDbObject(update), returnNew, upsert)); }
/** * 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(DBQuery.Query query, T object, boolean upsert, boolean multi, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.update( serializeQuery(query), convertToBasicDbObject(object), upsert, multi, concern)); }