Class FindOneAndReplaceOptions

java.lang.Object
com.mongodb.client.model.FindOneAndReplaceOptions

public class FindOneAndReplaceOptions extends Object
The options to apply to an operation that atomically finds a document and replaces it.
Since:
3.0
MongoDB documentation
reference/command/findAndModify/
  • Constructor Details

    • FindOneAndReplaceOptions

      public FindOneAndReplaceOptions()
  • Method Details

    • getProjection

      @Nullable public Bson getProjection()
      Gets a document describing the fields to return for all matching documents.
      Returns:
      the project document, which may be null
      MongoDB documentation
      Projection
    • projection

      public FindOneAndReplaceOptions projection(@Nullable Bson projection)
      Sets a document describing the fields to return for all matching documents.
      Parameters:
      projection - the project document, which may be null.
      Returns:
      this
      See Also:
      MongoDB documentation
      Projection
    • getSort

      @Nullable public Bson getSort()
      Gets the sort criteria to apply to the query. The default is null, which means that the documents will be returned in an undefined order.
      Returns:
      a document describing the sort criteria
      MongoDB documentation
      Sort
    • sort

      Sets the sort criteria to apply to the query.
      Parameters:
      sort - the sort criteria, which may be null.
      Returns:
      this
      MongoDB documentation
      Sort
    • isUpsert

      public boolean isUpsert()
      Returns true if a new document should be inserted if there are no matches to the query filter. The default is false.
      Returns:
      true if a new document should be inserted if there are no matches to the query filter
    • upsert

      public FindOneAndReplaceOptions upsert(boolean upsert)
      Set to true if a new document should be inserted if there are no matches to the query filter.
      Parameters:
      upsert - true if a new document should be inserted if there are no matches to the query filter
      Returns:
      this
    • getReturnDocument

      public ReturnDocument getReturnDocument()
      Gets the ReturnDocument value indicating whether to return the document before it was replaced or after
      Returns:
      ReturnDocument.BEFORE if returning the document before it was replaced otherwise return ReturnDocument.AFTER
    • returnDocument

      public FindOneAndReplaceOptions returnDocument(ReturnDocument returnDocument)
      Set whether to return the document before it was replaced or after
      Parameters:
      returnDocument - set whether to return the document before it was replaced or after
      Returns:
      this
    • maxTime

      public FindOneAndReplaceOptions maxTime(long maxTime, TimeUnit timeUnit)
      Sets the maximum execution time on the server for this operation.
      Parameters:
      maxTime - the max time
      timeUnit - the time unit, which may not be null
      Returns:
      this
    • getMaxTime

      public long getMaxTime(TimeUnit timeUnit)
      Gets the maximum execution time for the find one and replace operation.
      Parameters:
      timeUnit - the time unit for the result
      Returns:
      the max time
    • getBypassDocumentValidation

      @Nullable public Boolean getBypassDocumentValidation()
      Gets the bypass document level validation flag
      Returns:
      the bypass document level validation flag
      Since:
      3.2
      Since server release
      3.2
    • bypassDocumentValidation

      public FindOneAndReplaceOptions bypassDocumentValidation(@Nullable Boolean bypassDocumentValidation)
      Sets the bypass document level validation flag.
      Parameters:
      bypassDocumentValidation - If true, allows the write to opt-out of document level validation.
      Returns:
      this
      Since:
      3.2
      Since server release
      3.2
    • getCollation

      @Nullable public Collation getCollation()
      Returns the collation options
      Returns:
      the collation options
      Since:
      3.4
      Since server release
      3.4
    • collation

      public FindOneAndReplaceOptions collation(@Nullable Collation collation)
      Sets the collation options

      A null value represents the server default.

      Parameters:
      collation - the collation options to use
      Returns:
      this
      Since:
      3.4
      Since server release
      3.4
    • getHint

      @Nullable public Bson getHint()
      Returns the hint for which index to use. The default is not to set a hint.
      Returns:
      the hint
      Since:
      4.1
    • hint

      Sets the hint for which index to use. A null value means no hint is set.
      Parameters:
      hint - the hint
      Returns:
      this
      Since:
      4.1
    • getHintString

      @Nullable public String getHintString()
      Gets the hint string to apply.
      Returns:
      the hint string, which should be the name of an existing index
      Since:
      4.1
    • hintString

      public FindOneAndReplaceOptions hintString(@Nullable String hint)
      Sets the hint to apply.
      Parameters:
      hint - the name of the index which should be used for the operation
      Returns:
      this
      Since:
      4.1
    • getComment

      @Nullable public BsonValue getComment()
      Returns:
      the comment for this operation. A null value means no comment is set.
      Since:
      4.6
      Since server release
      4.4
    • comment

      public FindOneAndReplaceOptions comment(@Nullable String comment)
      Sets the comment for this operation. A null value means no comment is set.
      Parameters:
      comment - the comment
      Returns:
      this
      Since:
      4.6
      Since server release
      4.4
    • comment

      public FindOneAndReplaceOptions comment(@Nullable BsonValue comment)
      Sets the comment for this operation. A null value means no comment is set.
      Parameters:
      comment - the comment
      Returns:
      this
      Since:
      4.6
      Since server release
      4.4
    • getLet

      @Nullable public Bson getLet()
      Add top-level variables to the operation
      Returns:
      the top level variables if set or null.
      Since:
      4.6
      Since server release
      5.0
    • let

      public FindOneAndReplaceOptions let(Bson variables)
      Add top-level variables for the operation

      Allows for improved command readability by separating the variables from the query text.

      Parameters:
      variables - for the operation or null
      Returns:
      this
      Since:
      4.6
      Since server release
      5.0
    • toString

      public String toString()
      Overrides:
      toString in class Object