@Nullable
    public DBObject findAndModify(@Nullable final DBObject query, @Nullable final DBObject fields, @Nullable final DBObject sort,
                                  final boolean remove, @Nullable final DBObject update,
                                  final boolean returnNew, final boolean upsert,
                                  final long maxTime, final TimeUnit maxTimeUnit,
                                  final WriteConcern writeConcern) {
        return findAndModify(query != null ? query : new BasicDBObject(), new DBCollectionFindAndModifyOptions()
                .projection(fields)
                .sort(sort)
                .remove(remove)
                .update(update)
                .returnNew(returnNew)
                .upsert(upsert)
                .maxTime(maxTime, maxTimeUnit)
                .writeConcern(writeConcern));
    }
@Nullable
    public DBObject findAndModify(@Nullable final DBObject query, @Nullable final DBObject fields, @Nullable final DBObject sort,
                                  final boolean remove, @Nullable final DBObject update,
                                  final boolean returnNew, final boolean upsert,
                                  final long maxTime, final TimeUnit maxTimeUnit,
                                  final WriteConcern writeConcern) {
        return findAndModify(query != null ? query : new BasicDBObject(), new DBCollectionFindAndModifyOptions()
                .projection(fields)
                .sort(sort)
                .remove(remove)
                .update(update)
                .returnNew(returnNew)
                .upsert(upsert)
                .maxTime(maxTime, maxTimeUnit)
                .writeConcern(writeConcern));
    }
@ Nullable public DBObject findAndModify ( @ Nullable final DBObject query , @ Nullable final DBObject fields , @ Nullable final DBObject sort , final boolean remove , @ Nullable final DBObject update , final boolean returnNew , final boolean upsert , final long maxTime , final TimeUnit maxTimeUnit , final WriteConcern writeConcern ) { return findAndModify ( query != null ? query : new BasicDBObject ( ) , new DBCollectionFindAndModifyOptions ( ) . projection ( fields ) . sort ( sort ) . remove ( remove ) . update ( update ) . returnNew ( returnNew ) . upsert ( upsert ) . maxTime ( maxTime , maxTimeUnit ) . writeConcern ( writeConcern ) ) ; }
Atomically modify and return a single document. By default, the returned document does not include the modifications made on the
update.

@param query       specifies the selection criteria for the modification
@param fields      a subset of fields to return
@param sort        determines which document the operation will modify if the query selects multiple documents
@param remove      when {@code true}, removes the selected document
@param returnNew   when true, returns the modified document rather than the original
@param update      performs an update of the selected document
@param upsert      when true, operation creates a new document if the query returns no documents
@param maxTime     the maximum time that the server will allow this operation to execute before killing it. A non-zero value requires
a server version &gt;= 2.6
@param maxTimeUnit the unit that maxTime is specified in
@param writeConcern the write concern to apply to this operation
@return the document as it was before the modifications, unless {@code returnNew} is true, in which case it returns the document
after the changes were made
@throws WriteConcernException if the write failed due some other failure specific to the update command
@throws MongoException if the operation failed for some other reason
@mongodb.driver.manual reference/command/findAndModify/ Find and Modify
@since 2.14.0
Atomically modify and return a single document . By default the returned document does not include the modifications made on the update .