Search in sources :

Example 1 with DeleteOperation

use of com.mongodb.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 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, singletonList(deleteRequest)));
}
Also used : DeleteOperation(com.mongodb.operation.DeleteOperation) FindAndDeleteOperation(com.mongodb.operation.FindAndDeleteOperation) DeleteRequest(com.mongodb.bulk.DeleteRequest)

Aggregations

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