in mongodb/src/main/java/org/hibernate/ogm/datastore/mongodb/MongoDBDialect.java [1342:1372]
private static int doRemove(final MongoDBQueryDescriptor queryDesc, final MongoCollection<Document> collection, MongoDBQueryDescriptor.Operation operation) {
Document query = queryDesc.getCriteria();
Document options = queryDesc.getOptions();
Boolean justOne = FALSE;
WriteConcern wc = null;
if ( options != null ) {
justOne = (Boolean) options.get( "justOne" );
justOne = ( justOne != null ) ? justOne : FALSE;
Document o = (Document) options.get( "writeConcern" );
wc = getWriteConcern( o );
}
MongoCollection<Document> collectionWithConcern = collection.withWriteConcern( ( wc != null ? wc : collection.getWriteConcern() ) );
DeleteResult result = null;
switch ( operation ) {
case REMOVE:
result = justOne ? collectionWithConcern.deleteOne( query ) : collectionWithConcern.deleteMany( query );
break;
case DELETEONE:
result = collectionWithConcern.deleteOne( query ) ;
break;
case DELETEMANY:
result = collectionWithConcern.deleteMany( query );
break;
}
if ( result.wasAcknowledged() ) {
return (int) result.getDeletedCount();
}
return -1; // Not sure if we should throw an exception instead?
}