@Immutable public class WriteConcern extends java.lang.Object implements java.io.Serializable
Controls the acknowledgment of write operations with various options.
w
wtimeout - how long to wait for secondaries to acknowledge before failing
Other options:
journal: If true block until write operations have been committed to the journal. Cannot be used in combination with
fsync. 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.| 限定符和类型 | 类和说明 |
|---|---|
static class |
WriteConcern.Majority
已过时。
|
| 限定符和类型 | 字段和说明 |
|---|---|
static WriteConcern |
ACKNOWLEDGED
Write operations that use this write concern will wait for acknowledgement, using the default write concern configured on the server.
|
static WriteConcern |
FSYNC_SAFE
已过时。
Prefer
JOURNALED |
static WriteConcern |
FSYNCED
已过时。
Prefer
JOURNALED |
static WriteConcern |
JOURNAL_SAFE
已过时。
Prefer
JOURNALED |
static WriteConcern |
JOURNALED
Write operations wait for the server to group commit to the journal file on disk.
|
static WriteConcern |
MAJORITY
Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation.
|
static WriteConcern |
NORMAL
已过时。
Prefer
UNACKNOWLEDGED |
static WriteConcern |
REPLICA_ACKNOWLEDGED
已过时。
Prefer WriteConcern#W2
|
static WriteConcern |
REPLICAS_SAFE
已过时。
Prefer
W2 |
static WriteConcern |
SAFE
已过时。
Prefer
ACKNOWLEDGED |
static WriteConcern |
UNACKNOWLEDGED
Write operations that use this write concern will return as soon as the message is written to the socket.
|
static WriteConcern |
W1
Write operations that use this write concern will wait for acknowledgement from a single member.
|
static WriteConcern |
W2
Write operations that use this write concern will wait for acknowledgement from two members.
|
static WriteConcern |
W3
Write operations that use this write concern will wait for acknowledgement from three members.
|
| 构造器和说明 |
|---|
WriteConcern()
已过时。
Prefer
UNACKNOWLEDGED |
WriteConcern(boolean fsync)
已过时。
prefer
JOURNALED or withJournal(Boolean) |
WriteConcern(int w)
Construct an instance with the given integer-based value for w.
|
WriteConcern(int w,
int wTimeoutMS)
Constructs an instance with the given integer-based value for w and the given value for wTimeoutMS.
|
WriteConcern(int w,
int wTimeoutMS,
boolean fsync)
已过时。
|
WriteConcern(int w,
int wTimeoutMS,
boolean fsync,
boolean journal)
已过时。
|
WriteConcern(java.lang.String w)
Construct an instance with the given tag set-based value for w.
|
WriteConcern(java.lang.String w,
int wTimeoutMS,
boolean fsync,
boolean journal)
已过时。
|
| 限定符和类型 | 方法和说明 |
|---|---|
BsonDocument |
asDocument()
Gets this write concern as a document.
|
boolean |
callGetLastError()
已过时。
Prefer
isAcknowledged() |
boolean |
equals(java.lang.Object o) |
boolean |
fsync()
已过时。
Prefer
getJournal() |
boolean |
getFsync()
已过时。
Prefer
getJournal() |
boolean |
getJ()
已过时。
Prefer
getJournal() |
java.lang.Boolean |
getJournal()
Gets the journal property.
|
int |
getW()
Gets the w value as an integer.
|
java.lang.Object |
getWObject()
Gets the w value.
|
java.lang.String |
getWString()
Gets the w parameter as a String.
|
int |
getWtimeout()
已过时。
Prefer
getWTimeout(TimeUnit) |
java.lang.Integer |
getWTimeout(java.util.concurrent.TimeUnit timeUnit)
Gets the wTimeout in the given time unit.
|
int |
hashCode() |
boolean |
isAcknowledged()
Returns true if this write concern indicates that write operations must be acknowledged.
|
boolean |
isServerDefault()
Gets whether this write concern indicates that the server's default write concern will be used.
|
static WriteConcern.Majority |
majorityWriteConcern(int wtimeout,
boolean fsync,
boolean j)
已过时。
|
java.lang.String |
toString() |
static WriteConcern |
valueOf(java.lang.String name)
Gets the WriteConcern constants by name (matching is done case insensitively).
|
WriteConcern |
withFsync(boolean fsync)
已过时。
Prefer
withJournal(Boolean) |
WriteConcern |
withJ(boolean journal)
已过时。
Prefer
withJournal(Boolean) |
WriteConcern |
withJournal(java.lang.Boolean journal)
Constructs a new WriteConcern from the current one and the specified journal value
|
WriteConcern |
withW(int w)
Constructs a new WriteConcern from the current one and the specified integer-based value for w
|
WriteConcern |
withW(java.lang.String w)
Constructs a new WriteConcern from the current one and the specified tag-set based value for w
|
WriteConcern |
withWTimeout(long wTimeout,
java.util.concurrent.TimeUnit timeUnit)
Constructs a new WriteConcern from the current one and the specified wTimeout in the given time unit.
|
public static final WriteConcern ACKNOWLEDGED
public static final WriteConcern W1
public static final WriteConcern W2
public static final WriteConcern W3
public static final WriteConcern UNACKNOWLEDGED
@Deprecated public static final WriteConcern FSYNCED
JOURNALEDpublic static final WriteConcern JOURNALED
@Deprecated public static final WriteConcern REPLICA_ACKNOWLEDGED
@Deprecated public static final WriteConcern NORMAL
UNACKNOWLEDGEDWrite 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.
UNACKNOWLEDGED@Deprecated public static final WriteConcern SAFE
ACKNOWLEDGEDWrite 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.
ACKNOWLEDGEDpublic static final WriteConcern MAJORITY
@Deprecated public static final WriteConcern FSYNC_SAFE
JOURNALEDExceptions 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.
FSYNCED@Deprecated public static final WriteConcern JOURNAL_SAFE
JOURNALEDExceptions 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.
@Deprecated public static final WriteConcern REPLICAS_SAFE
W2Exceptions 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.
W2@Deprecated public WriteConcern()
UNACKNOWLEDGEDWriteConcern#UNACKNOWLEDGEDUNACKNOWLEDGEDpublic WriteConcern(int w)
w - number of servers to ensure write propagation to before acknowledgment, which must be >= 0public WriteConcern(java.lang.String w)
public WriteConcern(int w,
int wTimeoutMS)
w - the w value, which must be >= 0wTimeoutMS - the wTimeout in milliseconds, which must be >= 0@Deprecated public WriteConcern(boolean fsync)
JOURNALED or withJournal(Boolean)fsync - whether or not to fsync@Deprecated
public WriteConcern(int w,
int wTimeoutMS,
boolean fsync)
withW(int), withWTimeout(long, TimeUnit), withJournal(Boolean)w - the w value, which must be >= 0wTimeoutMS - the wTimeout in milliseconds, which must be >= 0fsync - whether or not to fsync@Deprecated
public WriteConcern(int w,
int wTimeoutMS,
boolean fsync,
boolean journal)
withW(int), withWTimeout(long, TimeUnit), withJournal(Boolean)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@Deprecated
public WriteConcern(java.lang.String w,
int wTimeoutMS,
boolean fsync,
boolean journal)
withW(String), withWTimeout(long, TimeUnit), withJournal(Boolean)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 commitpublic java.lang.Object getWObject()
public int getW()
java.lang.IllegalStateException - if w is null or not an integerpublic java.lang.String getWString()
java.lang.IllegalStateException - if w is null or not a Stringpublic java.lang.Integer getWTimeout(java.util.concurrent.TimeUnit timeUnit)
timeUnit - the non-null time unit for the result@Deprecated public int getWtimeout()
getWTimeout(TimeUnit)public java.lang.Boolean getJournal()
@Deprecated public boolean getJ()
getJournal()@Deprecated public boolean getFsync()
getJournal()@Deprecated public boolean fsync()
getJournal()@Deprecated public boolean callGetLastError()
isAcknowledged()public boolean isServerDefault()
public BsonDocument asDocument()
w <= 0public boolean isAcknowledged()
public static WriteConcern valueOf(java.lang.String name)
name - the name of the WriteConcernWriteConcern instancepublic boolean equals(java.lang.Object o)
equals 在类中 java.lang.Objectpublic int hashCode()
hashCode 在类中 java.lang.Objectpublic java.lang.String toString()
toString 在类中 java.lang.Objectpublic WriteConcern withW(int w)
w - number of servers to ensure write propagation to before acknowledgment, which must be >= 0public WriteConcern withW(java.lang.String w)
w - tag set, or "majority", representing the servers to ensure write propagation to before acknowledgment. Do not use string
representation of integer values for wwithW(int)@Deprecated public WriteConcern withFsync(boolean fsync)
withJournal(Boolean)fsync - true if the write concern needs to include fsyncpublic WriteConcern withJournal(java.lang.Boolean journal)
journal - true if journalling is required for acknowledgement, false if not, or null if unspecified@Deprecated public WriteConcern withJ(boolean journal)
withJournal(Boolean)journal - true if journalling is required for acknowledgementpublic WriteConcern withWTimeout(long wTimeout, java.util.concurrent.TimeUnit timeUnit)
wTimeout - the wTimeout, which must be >= 0 and <= Integer.MAX_VALUE after conversion to millisecondstimeUnit - the non-null time unit to apply to wTimeout@Deprecated public static WriteConcern.Majority majorityWriteConcern(int wtimeout, boolean fsync, boolean j)
MAJORITY, withWTimeout(long, TimeUnit), withJournal(Boolean)wtimeout - timeout for write operationfsync - whether or not to fsyncj - whether writes should wait for a journal group commit