Class WriteConcern
- java.lang.Object
 - 
- com.mongodb.WriteConcern
 
 
- 
- All Implemented Interfaces:
 java.io.Serializable
- Direct Known Subclasses:
 WriteConcern.Majority
@Immutable @Deprecated(since="2021-05-27") public class WriteConcern extends java.lang.Object implements java.io.Serializable
Deprecated.Usage of this API is not supported in AEM as a Cloud Service.Controls the acknowledgment of write operations with various options.
w- 0: Don't wait for acknowledgement from the server
 - 1: Wait for acknowledgement, but don't wait for secondaries to replicate
 - >=2: Wait for one or more secondaries to also acknowledge
 - "majority": Wait for a majority of data bearing nodes to acknowledge
 - "<tag set name>": Wait for one or more secondaries to also acknowledge based on a tag set name
 
wtimeout- how long to wait for secondaries to acknowledge before failing- 0: indefinite
 - >0: time to wait in milliseconds
 
Other options:
journal: If true block until write operations have been committed to the journal. Cannot be used in combination withfsync. Prior to MongoDB 2.6 this option was ignored if the server was running without journaling. Starting with MongoDB 2.6 write operations will fail with an exception if this option is used when the server is running without journaling.
- See Also:
 - Serialized Form
 
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWriteConcern.MajorityDeprecated. 
- 
Field Summary
Fields Modifier and Type Field Description static WriteConcernACKNOWLEDGEDDeprecated.Write operations that use this write concern will wait for acknowledgement, using the default write concern configured on the server.static WriteConcernFSYNC_SAFEDeprecated.PreferJOURNALEDstatic WriteConcernFSYNCEDDeprecated.PreferJOURNALEDstatic WriteConcernJOURNAL_SAFEDeprecated.PreferJOURNALEDstatic WriteConcernJOURNALEDDeprecated.Write operations wait for the server to group commit to the journal file on disk.static WriteConcernMAJORITYDeprecated.Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation.static WriteConcernNORMALDeprecated.PreferUNACKNOWLEDGEDstatic WriteConcernREPLICA_ACKNOWLEDGEDDeprecated.Prefer WriteConcern#W2static WriteConcernREPLICAS_SAFEDeprecated.PreferW2static WriteConcernSAFEDeprecated.PreferACKNOWLEDGEDstatic WriteConcernUNACKNOWLEDGEDDeprecated.Write operations that use this write concern will return as soon as the message is written to the socket.static WriteConcernW1Deprecated.Write operations that use this write concern will wait for acknowledgement from a single member.static WriteConcernW2Deprecated.Write operations that use this write concern will wait for acknowledgement from two members.static WriteConcernW3Deprecated.Write operations that use this write concern will wait for acknowledgement from three members. 
- 
Constructor Summary
Constructors Constructor Description WriteConcern()Deprecated.PreferUNACKNOWLEDGEDWriteConcern(boolean fsync)Deprecated.preferJOURNALEDorwithJournal(Boolean)WriteConcern(int w)Deprecated.Construct an instance with the given integer-based value for w.WriteConcern(int w, int wTimeoutMS)Deprecated.Constructs an instance with the given integer-based value for w and the given value for wTimeoutMS.WriteConcern(int w, int wTimeoutMS, boolean fsync)Deprecated.WriteConcern(int w, int wTimeoutMS, boolean fsync, boolean journal)Deprecated.WriteConcern(java.lang.String w)Deprecated.Construct an instance with the given tag set-based value for w.WriteConcern(java.lang.String w, int wTimeoutMS, boolean fsync, boolean journal)Deprecated. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description BsonDocumentasDocument()Deprecated.Gets this write concern as a document.booleancallGetLastError()Deprecated.PreferisAcknowledged()booleanequals(java.lang.Object o)Deprecated.booleanfsync()Deprecated.PrefergetJournal()booleangetFsync()Deprecated.PrefergetJournal()booleangetJ()Deprecated.PrefergetJournal()java.lang.BooleangetJournal()Deprecated.Gets the journal property.intgetW()Deprecated.Gets the w value as an integer.java.lang.ObjectgetWObject()Deprecated.Gets the w value.java.lang.StringgetWString()Deprecated.Gets the w parameter as a String.intgetWtimeout()Deprecated.PrefergetWTimeout(TimeUnit)java.lang.IntegergetWTimeout(java.util.concurrent.TimeUnit timeUnit)Deprecated.Gets the wTimeout in the given time unit.inthashCode()Deprecated.booleanisAcknowledged()Deprecated.Returns true if this write concern indicates that write operations must be acknowledged.booleanisServerDefault()Deprecated.Gets whether this write concern indicates that the server's default write concern will be used.static WriteConcern.MajoritymajorityWriteConcern(int wtimeout, boolean fsync, boolean j)Deprecated.java.lang.StringtoString()Deprecated.static WriteConcernvalueOf(java.lang.String name)Deprecated.Gets the WriteConcern constants by name (matching is done case insensitively).WriteConcernwithFsync(boolean fsync)Deprecated.PreferwithJournal(Boolean)WriteConcernwithJ(boolean journal)Deprecated.PreferwithJournal(Boolean)WriteConcernwithJournal(java.lang.Boolean journal)Deprecated.Constructs a new WriteConcern from the current one and the specified journal valueWriteConcernwithW(int w)Deprecated.Constructs a new WriteConcern from the current one and the specified integer-based value for wWriteConcernwithW(java.lang.String w)Deprecated.Constructs a new WriteConcern from the current one and the specified tag-set based value for wWriteConcernwithWTimeout(long wTimeout, java.util.concurrent.TimeUnit timeUnit)Deprecated.Constructs a new WriteConcern from the current one and the specified wTimeout in the given time unit. 
 - 
 
- 
- 
Field Detail
- 
ACKNOWLEDGED
public static final WriteConcern ACKNOWLEDGED
Deprecated.Write operations that use this write concern will wait for acknowledgement, using the default write concern configured on the server.- Since:
 - 2.10.0
 
 
- 
W1
public static final WriteConcern W1
Deprecated.Write operations that use this write concern will wait for acknowledgement from a single member.- Since:
 - 3.2
 
 
- 
W2
public static final WriteConcern W2
Deprecated.Write operations that use this write concern will wait for acknowledgement from two members.- Since:
 - 3.2
 
 
- 
W3
public static final WriteConcern W3
Deprecated.Write operations that use this write concern will wait for acknowledgement from three members.- Since:
 - 3.2
 
 
- 
UNACKNOWLEDGED
public static final WriteConcern UNACKNOWLEDGED
Deprecated.Write operations that use this write concern will return as soon as the message is written to the socket. Exceptions are raised for network issues, but not server errors.- Since:
 - 2.10.0
 
 
- 
FSYNCED
@Deprecated public static final WriteConcern FSYNCED
Deprecated.PreferJOURNALEDWrite operations wait for the server to flush the data to disk. 
- 
JOURNALED
public static final WriteConcern JOURNALED
Deprecated.Write operations wait for the server to group commit to the journal file on disk. 
- 
REPLICA_ACKNOWLEDGED
@Deprecated public static final WriteConcern REPLICA_ACKNOWLEDGED
Deprecated.Prefer WriteConcern#W2Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation. 
- 
NORMAL
@Deprecated public static final WriteConcern NORMAL
Deprecated.PreferUNACKNOWLEDGEDWrite operations that use this write concern will return as soon as the message is written to the socket. Exceptions are raised for network issues, but not server errors.
This field has been superseded by
WriteConcern.UNACKNOWLEDGED, and may be deprecated in a future release.- See Also:
 UNACKNOWLEDGED
 
- 
SAFE
@Deprecated public static final WriteConcern SAFE
Deprecated.PreferACKNOWLEDGEDWrite operations that use this write concern will wait for acknowledgement from the primary server before returning. Exceptions are raised for network issues, and server errors.
This field has been superseded by
WriteConcern.ACKNOWLEDGED, and may be deprecated in a future release.- See Also:
 ACKNOWLEDGED
 
- 
MAJORITY
public static final WriteConcern MAJORITY
Deprecated.Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation. 
- 
FSYNC_SAFE
@Deprecated public static final WriteConcern FSYNC_SAFE
Deprecated.PreferJOURNALEDExceptions are raised for network issues, and server errors; the write operation waits for the server to flush the data to disk.
This field has been superseded by
WriteConcern.FSYNCED, and may be deprecated in a future release.- See Also:
 FSYNCED
 
- 
JOURNAL_SAFE
@Deprecated public static final WriteConcern JOURNAL_SAFE
Deprecated.PreferJOURNALEDExceptions are raised for network issues, and server errors; the write operation waits for the server to group commit to the journal file on disk.
This field has been superseded by
WriteConcern.JOURNALED, and may be deprecated in a future release. 
- 
REPLICAS_SAFE
@Deprecated public static final WriteConcern REPLICAS_SAFE
Deprecated.PreferW2Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation.
This field has been superseded by
WriteConcern.REPLICA_ACKNOWLEDGED, and may be deprecated in a future release.- See Also:
 W2
 
 - 
 
- 
Constructor Detail
- 
WriteConcern
@Deprecated public WriteConcern()
Deprecated.PreferUNACKNOWLEDGEDConstructs an instance with all properties initialized to their default values, except for w, which is initialized to 0, making instances constructed this ways equivalent toWriteConcern#UNACKNOWLEDGED- See Also:
 UNACKNOWLEDGED
 
- 
WriteConcern
public WriteConcern(int w)
Deprecated.Construct an instance with the given integer-based value for w.- Parameters:
 w- number of servers to ensure write propagation to before acknowledgment, which must be>= 0
 
- 
WriteConcern
public WriteConcern(java.lang.String w)
Deprecated.Construct an instance with the given tag set-based value for w.- Parameters:
 w- tag set name, or "majority", representing the servers to ensure write propagation to before acknowledgment. Do not use string representation of integer values for w
 
- 
WriteConcern
public WriteConcern(int w, int wTimeoutMS)Deprecated.Constructs an instance with the given integer-based value for w and the given value for wTimeoutMS.- Parameters:
 w- the w value, which must be >= 0wTimeoutMS- the wTimeout in milliseconds, which must be >= 0
 
- 
WriteConcern
@Deprecated public WriteConcern(boolean fsync)
Deprecated.preferJOURNALEDorwithJournal(Boolean)Constructs an instance with the given value for fsync.- Parameters:
 fsync- whether or not to fsync
 
- 
WriteConcern
@Deprecated public WriteConcern(int w, int wTimeoutMS, boolean fsync)Deprecated.Constructs an instance with the given integer-based w value, wTimeout in milliseconds, and fsync value.- Parameters:
 w- the w value, which must be >= 0wTimeoutMS- the wTimeout in milliseconds, which must be >= 0fsync- whether or not to fsync
 
- 
WriteConcern
@Deprecated public WriteConcern(int w, int wTimeoutMS, boolean fsync, boolean journal)Deprecated.Constructs an instance with the given integer-based w value, wTimeout in milliseconds, fsync value, and journal value.- Parameters:
 w- the w value, which must be >= 0wTimeoutMS- the wTimeout in milliseconds, which must be >= 0fsync- whether or not to fsyncjournal- whether writes should wait for a journaling group commit
 
- 
WriteConcern
@Deprecated public WriteConcern(java.lang.String w, int wTimeoutMS, boolean fsync, boolean journal)Deprecated.Constructs an instance with the given String-based w value, wTimeout in milliseconds, fsync value, and journal value.- Parameters:
 w- the w value, which must be non-nullwTimeoutMS- the wTimeout in milliseconds, which must be >= 0fsync- whether or not to fsyncjournal- whether writes should wait for a journaling group commit
 
 - 
 
- 
Method Detail
- 
getWObject
public java.lang.Object getWObject()
Deprecated.Gets the w value.- Returns:
 - w, either an instance of Integer or String or null
 
 
- 
getW
public int getW()
Deprecated.Gets the w value as an integer.- Returns:
 - w as an int
 - Throws:
 java.lang.IllegalStateException- if w is null or not an integer
 
- 
getWString
public java.lang.String getWString()
Deprecated.Gets the w parameter as a String.- Returns:
 - w as a String
 - Throws:
 java.lang.IllegalStateException- if w is null or not a String
 
- 
getWTimeout
@Nullable public java.lang.Integer getWTimeout(java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets the wTimeout in the given time unit.- Parameters:
 timeUnit- the non-null time unit for the result- Returns:
 - the WTimeout, which may be null if a wTimeout has not been specified
 - Since:
 - 3.2
 
 
- 
getWtimeout
@Deprecated public int getWtimeout()
Deprecated.PrefergetWTimeout(TimeUnit)Gets the wTimeout in milliseconds. If wTimeout has not been specified, returns 0.- Returns:
 - the wTimeout in milliseconds
 
 
- 
getJournal
public java.lang.Boolean getJournal()
Deprecated.Gets the journal property. The default value is null.- Returns:
 - whether journal syncing is enabled, or null if unspecified.
 - Since:
 - 3.2
 
 
- 
getJ
@Deprecated public boolean getJ()
Deprecated.PrefergetJournal()Gets the journal property. If journal has not been specified, returns false.- Returns:
 - true if journal is true, false if it false or unspecified.
 
 
- 
getFsync
@Deprecated public boolean getFsync()
Deprecated.PrefergetJournal()Gets the fsync property. If fsync has not been specified, returns false.- Returns:
 - true if fsync is true, false if it false or unspecified
 
 
- 
fsync
@Deprecated public boolean fsync()
Deprecated.PrefergetJournal()Gets the fsync property. If fsync has not been specified, returns false.- Returns:
 - true if fsync is true, false if it false or unspecified
 
 
- 
callGetLastError
@Deprecated public boolean callGetLastError()
Deprecated.PreferisAcknowledged()Returns true if this write concern indicates that write operations must be acknowledged.- Returns:
 - whether this write concern will result in an an acknowledged write
 
 
- 
isServerDefault
public boolean isServerDefault()
Deprecated.Gets whether this write concern indicates that the server's default write concern will be used.- Returns:
 - true if this write concern indicates that the server's default write concern will be used
 
 
- 
asDocument
public BsonDocument asDocument()
Deprecated.Gets this write concern as a document.- Returns:
 - The write concern as a BsonDocument, even if 
w <= 0 
 
- 
isAcknowledged
public boolean isAcknowledged()
Deprecated.Returns true if this write concern indicates that write operations must be acknowledged.- Returns:
 - true w != null or w > 0 or journal is true or fsync is true
 
 
- 
valueOf
public static WriteConcern valueOf(java.lang.String name)
Deprecated.Gets the WriteConcern constants by name (matching is done case insensitively).- Parameters:
 name- the name of the WriteConcern- Returns:
 - the 
WriteConcern instance 
 
- 
equals
public boolean equals(java.lang.Object o)
Deprecated.- Overrides:
 equalsin classjava.lang.Object
 
- 
hashCode
public int hashCode()
Deprecated.- Overrides:
 hashCodein classjava.lang.Object
 
- 
toString
public java.lang.String toString()
Deprecated.- Overrides:
 toStringin classjava.lang.Object
 
- 
withW
public WriteConcern withW(int w)
Deprecated.Constructs a new WriteConcern from the current one and the specified integer-based value for w- Parameters:
 w- number of servers to ensure write propagation to before acknowledgment, which must be>= 0- Returns:
 - the new WriteConcern
 
 
- 
withW
public WriteConcern withW(java.lang.String w)
Deprecated.Constructs a new WriteConcern from the current one and the specified tag-set based value for w- Parameters:
 w- tag set, or "majority", representing the servers to ensure write propagation to before acknowledgment. Do not use string representation of integer values for w- Returns:
 - the new WriteConcern
 - See Also:
 withW(int)
 
- 
withFsync
@Deprecated public WriteConcern withFsync(boolean fsync)
Deprecated.PreferwithJournal(Boolean)Constructs a new WriteConcern from the current one and the specified fsync value- Parameters:
 fsync- true if the write concern needs to include fsync- Returns:
 - the new WriteConcern
 
 
- 
withJournal
public WriteConcern withJournal(java.lang.Boolean journal)
Deprecated.Constructs a new WriteConcern from the current one and the specified journal value- Parameters:
 journal- true if journalling is required for acknowledgement, false if not, or null if unspecified- Returns:
 - the new WriteConcern
 - Since:
 - 3.2
 
 
- 
withJ
@Deprecated public WriteConcern withJ(boolean journal)
Deprecated.PreferwithJournal(Boolean)Constructs a new WriteConcern from the current one and the specified journal value- Parameters:
 journal- true if journalling is required for acknowledgement- Returns:
 - the new WriteConcern
 
 
- 
withWTimeout
public WriteConcern withWTimeout(long wTimeout, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Constructs a new WriteConcern from the current one and the specified wTimeout in the given time unit.- Parameters:
 wTimeout- the wTimeout, which must be >= 0 and <= Integer.MAX_VALUE after conversion to millisecondstimeUnit- the non-null time unit to apply to wTimeout- Returns:
 - the WriteConcern with the given wTimeout
 - Since:
 - 3.2
 
 
- 
majorityWriteConcern
@Deprecated public static WriteConcern.Majority majorityWriteConcern(int wtimeout, boolean fsync, boolean j)
Deprecated.Create a Majority Write Concern that requires a majority of servers to acknowledge the write.- Parameters:
 wtimeout- timeout for write operationfsync- whether or not to fsyncj- whether writes should wait for a journal group commit- Returns:
 - Majority, a subclass of WriteConcern that represents the write concern requiring most servers to acknowledge the write
 
 
 - 
 
 -