Search in sources :

Example 1 with DeleteOperation

use of com.mongodb.internal.operation.DeleteOperation in project mongo-java-driver by mongodb.

the class DBCollection method remove.

/**
 * Remove documents from a collection.
 *
 * @param query   the deletion criteria using query operators. Omit the query parameter or pass an empty document to delete all
 *                documents in the collection.
 * @param options the options to apply to the delete operation
 * @return the result of the operation
 * @throws com.mongodb.WriteConcernException if the write failed due some other failure specific to the delete command
 * @throws com.mongodb.MongoCommandException if the write failed due to a specific command exception
 * @throws MongoException if the operation failed for some other reason
 * @mongodb.driver.manual tutorial/remove-documents/ Remove Documents
 * @since 3.4
 */
public WriteResult remove(final DBObject query, final DBCollectionRemoveOptions options) {
    notNull("query", query);
    notNull("options", options);
    WriteConcern writeConcern = options.getWriteConcern() != null ? options.getWriteConcern() : getWriteConcern();
    DeleteRequest deleteRequest = new DeleteRequest(wrap(query, options.getEncoder())).collation(options.getCollation());
    return executeWriteOperation(new DeleteOperation(getNamespace(), false, writeConcern, retryWrites, singletonList(deleteRequest)));
}
Also used : FindAndDeleteOperation(com.mongodb.internal.operation.FindAndDeleteOperation) DeleteOperation(com.mongodb.internal.operation.DeleteOperation) DeleteRequest(com.mongodb.internal.bulk.DeleteRequest)

Aggregations

DeleteRequest (com.mongodb.internal.bulk.DeleteRequest)1 DeleteOperation (com.mongodb.internal.operation.DeleteOperation)1 FindAndDeleteOperation (com.mongodb.internal.operation.FindAndDeleteOperation)1