MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / WriteConcern

Class WriteConcern

pymongo/write_concern.py:34–141  ·  view source on GitHub ↗

WriteConcern :param w: (integer or string) Used with replication, write operations will block until they have been replicated to the specified number or tagged set of servers. `w= ` always includes the replica set primary (e.g. w=3 means write to the primar

Source from the content-addressed store, hash-verified

32
33
34class WriteConcern:
35 """WriteConcern
36
37 :param w: (integer or string) Used with replication, write operations
38 will block until they have been replicated to the specified number
39 or tagged set of servers. `w=<integer>` always includes the replica
40 set primary (e.g. w=3 means write to the primary and wait until
41 replicated to **two** secondaries). **w=0 disables acknowledgement
42 of write operations and can not be used with other write concern
43 options.**
44 :param wtimeout: (integer) **DEPRECATED** Used in conjunction with `w`.
45 Specify a value in milliseconds to control how long to wait for write
46 propagation to complete. If replication does not complete in the given
47 timeframe, a timeout exception is raised.
48 :param j: If ``True`` block until write operations have been committed
49 to the journal. Cannot be used in combination with `fsync`. Write
50 operations will fail with an exception if this option is used when
51 the server is running without journaling.
52 :param fsync: If ``True`` and the server is running without journaling,
53 blocks until the server has synced all data files to disk. If the
54 server is running with journaling, this acts the same as the `j`
55 option, blocking until write operations have been committed to the
56 journal. Cannot be used in combination with `j`.
57
58
59 .. versionchanged:: 4.7
60 Deprecated parameter ``wtimeout``, use :meth:`~pymongo.timeout`.
61 """
62
63 __slots__ = ("__document", "__acknowledged", "__server_default")
64
65 def __init__(
66 self,
67 w: Optional[Union[int, str]] = None,
68 wtimeout: Optional[int] = None,
69 j: Optional[bool] = None,
70 fsync: Optional[bool] = None,
71 ) -> None:
72 self.__document: dict[str, Any] = {}
73 self.__acknowledged = True
74
75 if wtimeout is not None:
76 if not isinstance(wtimeout, int):
77 raise TypeError(f"wtimeout must be an integer, not {type(wtimeout)}")
78 if wtimeout < 0:
79 raise ValueError("wtimeout cannot be less than 0")
80 self.__document["wtimeout"] = wtimeout
81
82 if j is not None:
83 validate_boolean("j", j)
84 self.__document["j"] = j
85
86 if fsync is not None:
87 validate_boolean("fsync", fsync)
88 if j and fsync:
89 raise ConfigurationError("Can't set both j and fsync at the same time")
90 self.__document["fsync"] = fsync
91

Calls

no outgoing calls