/** * Removes objects from the database collection. * * @param object 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(T object, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(convertToDbObject(object), concern)); }
@Path("bar") @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Bar addBar(Bar bar) { WriteResult<Bar, String> result = getJacksonDBCollection().insert(bar); return result.getSavedObject(); }
/** * Get the object that was saved. This will contain the updated ID if the ID was generated. * <p/> * Note, this operation is a little expensive because it has to deserialise the object. If you just want the ID, * call getSavedId() instead. * * @return The saved object * @throws MongoException If no objects were saved */ public T getSavedObject() { if (dbObjects.length == 0) { throw new MongoException("No objects to return"); } return getSavedObjects()[0]; }
/** * calls {@link DBCollection#remove(com.mongodb.DBObject, com.mongodb.WriteConcern)} with the default WriteConcern * * @param id the id of the document to remove * @return The write result * @throws MongoException If an error occurred */ public WriteResult<T, K> removeById(K id) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(createIdQuery(id))); }
/** * Get the object that was saved. This will contain the updated ID if the ID was generated. * <p/> * Note, this operation is a little expensive because it has to deserialise the object. If you just want the ID, * call getSavedId() instead. * * @return The saved object * @throws MongoException If no objects were saved */ public T getSavedObject() { if (dbObjects.length == 0) { throw new MongoException("No objects to return"); } return getSavedObjects().get(0); }
/** * 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)); }
/** * Removes objects from the database collection. * * @param object 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(T object, WriteConcern concern) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(convertToDbObject(object), concern)); }
/** * 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)); }
/** * Saves an object to this collection (does insert or update based on the object _id). * * @param object the <code>DBObject</code> to save * @param concern the write concern * @return The result * @throws MongoException If an error occurred */ public WriteResult<T, K> save(T object, WriteConcern concern) throws MongoException { DBObject dbObject = convertToDbObject(object); return new WriteResult<T, K>(this, dbCollection.save(dbObject, concern), dbObject); }
/** * 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))); }
/** * Saves an object to this collection (does insert or update based on the object _id). * * @param object the <code>DBObject</code> to save * @param concern the write concern * @return The result * @throws MongoException If an error occurred */ public WriteResult<T, K> save(T object, WriteConcern concern) throws MongoException { DBObject dbObject = convertToDbObject(object); return new WriteResult<T, K>(this, dbCollection.save(dbObject, concern), dbObject); }
/** * 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 object the object that documents to be removed must match * @return The write result * @throws MongoException If an error occurred */ public WriteResult<T, K> remove(T object) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(convertToDbObject(object))); }
/** * calls {@link DBCollection#remove(com.mongodb.DBObject, com.mongodb.WriteConcern)} with the default WriteConcern * * @param id the id of the document to remove * @return The write result * @throws MongoException If an error occurred */ public WriteResult<T, K> removeById(K id) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(createIdQuery(id))); }
/** * calls {@link DBCollection#remove(com.mongodb.DBObject, com.mongodb.WriteConcern)} with the default WriteConcern * * @param object the object that documents to be removed must match * @return The write result * @throws MongoException If an error occurred */ public WriteResult<T, K> remove(T object) throws MongoException { return new WriteResult<T, K>(this, dbCollection.remove(convertToDbObject(object))); }
/** * Inserts an object into the database. * if the objects _id is null, one will be generated * you can get the _id that was generated by calling getSavedObject() or getSavedId() on the result * * @param object The object to insert * @return The result * @throws MongoException If an error occurred */ public WriteResult<T, K> insert(T object) throws MongoException { DBObject dbObject = convertToDbObject(object); return new WriteResult<T, K>(this, dbCollection.insert(dbObject), dbObject); }
/** * Inserts an object into the database. * if the objects _id is null, one will be generated * you can get the _id that was generated by calling getSavedObject() or getSavedId() on the result * * @param object The object to insert * @return The result * @throws MongoException If an error occurred */ public WriteResult<T, K> insert(T object) throws MongoException { DBObject dbObject = convertToDbObject(object); return new WriteResult<T, K>(this, dbCollection.insert(dbObject), dbObject); }
/** * Inserts objects into the database. * if the objects _id is null, one will be generated * you can get the _id that were generated by calling getSavedObjects() or getSavedIds() on the result * * @param objects The objects to insert * @return The result * @throws MongoException If an error occurred */ public WriteResult<T, K> insert(T... objects) throws MongoException { DBObject[] dbObjects = convertToDbObjects(objects); return new WriteResult<T, K>(this, dbCollection.insert(dbObjects), dbObjects); }
/** * Inserts objects into the database. * if the objects _id is null, one will be generated * you can get the _id that were generated by calling getSavedObjects() or getSavedIds() on the result * * @param objects The objects to insert * @param concern the write concern * @return The result * @throws MongoException If an error occurred */ public WriteResult<T, K> insert(WriteConcern concern, T... objects) throws MongoException { DBObject[] dbObjects = convertToDbObjects(objects); return new WriteResult<T, K>(this, dbCollection.insert(concern, dbObjects), dbObjects); }
/** * Inserts objects into the database. * if the objects _id is null, one will be generated * you can get the _id that were generated by calling getSavedObjects() or getSavedIds() on the result * * @param objects The objects to insert * @return The result * @throws MongoException If an error occurred */ public WriteResult<T, K> insert(T... objects) throws MongoException { DBObject[] dbObjects = convertToDbObjects(objects); return new WriteResult<T, K>(this, dbCollection.insert(dbObjects), dbObjects); }