Skip to content

Commit ddb6614

Browse files
authored
PYTHON-2682 Add support for the comment field to all helpers (mongodb#847)
1 parent b7057ec commit ddb6614

22 files changed

+4048
-48
lines changed

pymongo/aggregation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(
3939
let=None,
4040
user_fields=None,
4141
result_processor=None,
42+
comment=None,
4243
):
4344
if "explain" in options:
4445
raise ConfigurationError(
@@ -57,6 +58,8 @@ def __init__(
5758
if let:
5859
common.validate_is_mapping("let", let)
5960
options["let"] = let
61+
if comment is not None:
62+
options["comment"] = comment
6063
self._options = options
6164

6265
# This is the batchSize that will be used for setting the initial

pymongo/bulk.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ def _raise_bulk_write_error(full_result):
138138
class _Bulk(object):
139139
"""The private guts of the bulk write API."""
140140

141-
def __init__(self, collection, ordered, bypass_document_validation):
141+
def __init__(self, collection, ordered, bypass_document_validation, comment=None):
142142
"""Initialize a _Bulk instance."""
143143
self.collection = collection.with_options(
144144
codec_options=collection.codec_options._replace(
145145
unicode_decode_error_handler="replace", document_class=dict
146146
)
147147
)
148+
self.comment = comment
148149
self.ordered = ordered
149150
self.ops = []
150151
self.executed = False
@@ -308,6 +309,8 @@ def _execute_command(
308309
write_concern = final_write_concern or write_concern
309310

310311
cmd = SON([(cmd_name, self.collection.name), ("ordered", self.ordered)])
312+
if self.comment:
313+
cmd["comment"] = self.comment
311314
if not write_concern.is_server_default:
312315
cmd["writeConcern"] = write_concern.document
313316
if self.bypass_doc_val:

pymongo/change_stream.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def __init__(
9595
start_at_operation_time: Optional[Timestamp],
9696
session: Optional["ClientSession"],
9797
start_after: Optional[Mapping[str, Any]],
98+
comment: Optional[Any] = None,
9899
) -> None:
99100
if pipeline is None:
100101
pipeline = []
@@ -125,7 +126,7 @@ def __init__(
125126
self._collation = collation
126127
self._start_at_operation_time = start_at_operation_time
127128
self._session = session
128-
129+
self._comment = comment
129130
# Initialize cursor.
130131
self._cursor = self._create_cursor()
131132

@@ -209,8 +210,8 @@ def _run_aggregation_cmd(self, session, explicit_session):
209210
self._command_options(),
210211
explicit_session,
211212
result_processor=self._process_result,
213+
comment=self._comment,
212214
)
213-
214215
return self._client._retryable_read(
215216
cmd.get_cursor, self._target._read_preference_for(session), session
216217
)

0 commit comments

Comments
 (0)