WriteConcern¶
class WriteConcern(
val acknowledgment: WriteAcknowledgment? = null,
val writeToJournal: Boolean? = null,
val writeTimeout: Duration? = null
)
The level of acknowledgment requested from a write operation.
Constructors¶
WriteConcern¶
constructor(
acknowledgment: WriteAcknowledgment? = null,
writeToJournal: Boolean? = null,
writeTimeout: Duration? = null
)
Types¶
Companion¶
object Companion
Properties¶
acknowledgment¶
Describes how many nodes must acknowledge the write operation.
For the different options, see:
-
WriteAcknowledgment.Majority: majority of the nodes. -
WriteAcknowledgment.Nodes: a given number of nodes. -
WriteAcknowledgment.Tagged: specific nodes selected ahead of time.
If this field is null (default), the MongoDB default acknowledgment applies, which is WriteAcknowledgment.Majority in most deployments.
Example¶
collections.updateMany(
options = {
writeConcern(WriteConcern(WriteAcknowledgment.Nodes(2))
}
) {
User::age inc 1
}
External resources¶
See also
WithWriteConcern.writeConcern: Specify this option.
writeTimeout¶
val writeTimeout: Duration?
Specifies a time limit for a write operation to propagate to enough members to achieve acknowledgment and writeToJournal.
If acknowledgment is set to 0 or 1 nodes, this setting does nothing.
If the write operation cannot be acknowledged in less than this timeout, MongoDB returns a write concern exception, even if the operation may have later succeeded. In that case, the operations are not undone.
You may also be interested in the maxTime option.
If this option is set to null and the acknowledgment and writeToJournal options are unachievable, the write operation will block indefinitely.
writeTimeout of 0 is equivalent to null.
Example¶
collections.updateMany(
options = {
writeConcern(WriteConcern(writeTimeout = 2.minutes))
}
) {
User::age inc 1
}
External resources¶
See also
WithWriteConcern.writeConcern: Specify this option.
writeToJournal¶
val writeToJournal: Boolean?
Specifies whether the write operation must acknowledge being written to the journal.
Once an operation has been written to the journal, it is much less likely that it will be rolled back, even if in case of failure. However, roll back may still happen. To learn more, see the journal documentation.
If set to true, the nodes specified by acknowledgment must additionally write the operation to their journal, which forces the journal to be written to disk.
If this field is null (default), the MongoDB default applies, which depends on the deployment configuration. For example, on some deployments, WriteAcknowledgment.Majority implies that writeToJournal is set to true. To avoid surprises, we recommend always specifying this option.
Example¶
collections.updateMany(
options = {
writeConcern(WriteConcern(writeToJournal = true))
}
) {
User::age inc 1
}
External resources¶
See also
WithWriteConcern.writeConcern: Specify this option.
Functions¶
copy¶
fun copy(
acknowledgment: WriteAcknowledgment? = null,
writeToJournal: Boolean? = null,
writeTimeout: Duration? = null
): WriteConcern