Skip to content

Commit 29da448

Browse files
jmikolakevinAlbs
andcommitted
CDRIVER-4199 comment option for CRUD methods and change streams
Sync unified change stream and CRUD tests with mongodb/specifications@b8371ea Comment option for bulkWrite, insert, update, delete, findAndModify, aggregate, and change stream operations. Attach cursor comment to getMore for MongoDB 4.4+ Surface entity_map_match error if expectResult fails. The entity_map_match error contains relevant information about the failed match (e.g. field path). This is consistent with error reporting for error.expectResult later in the function. Update server doc links for database, collection, index enumeration. Also moves the retryable reads include for listDatabases to be consistent with other pages. Use BSON_ASSERT_PARAM for non-null parameter assertions in mongoc-bulk-operation.c. Co-authored-by: Kevin Albertson <[email protected]>
1 parent 9ac2689 commit 29da448

38 files changed

+7584
-76
lines changed

build/generate-opts.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,24 @@ def __init__(self, items, **defaults):
156156
'help': 'A BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language.'
157157
})
158158

159+
comment_option_since_4_4 = ('comment', {
160+
'type': 'bson_value_t',
161+
'convert': '_mongoc_convert_bson_value_t',
162+
'help': 'A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.'
163+
})
164+
165+
comment_option_string_pre_4_4 = ('comment', {
166+
'type': 'bson_value_t',
167+
'convert': '_mongoc_convert_bson_value_t',
168+
'help': 'A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Only string values are supported prior to MongoDB 4.4.'
169+
})
170+
159171
opts_structs = OrderedDict([
160172
('mongoc_crud_opts_t', Shared([
161173
write_concern_option,
162174
session_option,
163175
validate_option,
176+
comment_option_since_4_4,
164177
])),
165178

166179
('mongoc_update_opts_t', Shared([
@@ -217,6 +230,7 @@ def __init__(self, items, **defaults):
217230
ordered_option,
218231
session_option,
219232
let_option,
233+
comment_option_since_4_4,
220234
], allow_extra=False, ordered='true')),
221235

222236
('mongoc_bulk_insert_opts_t', Struct([
@@ -279,6 +293,7 @@ def __init__(self, items, **defaults):
279293
('startAtOperationTime', {'type': 'timestamp', 'help': 'A ``Timestamp``. The change stream only provides changes that occurred at or after the specified timestamp. Any command run against the server will return an operation time that can be used here. This option is mutually exclusive with ``resumeAfter`` and ``startAfter``.'}),
280294
('maxAwaitTimeMS', {'type': 'int64_t', 'convert': '_mongoc_convert_int64_positive', 'help': 'An ``int64`` representing the maximum amount of time a call to :symbol:`mongoc_change_stream_next` will block waiting for data'}),
281295
('fullDocument', {'type': 'utf8', 'help': 'A UTF-8 string. Set this option to "updateLookup" to direct the change stream cursor to lookup the most current majority-committed version of the document associated to an update change stream event.'}),
296+
comment_option_string_pre_4_4,
282297
], fullDocument="default")),
283298

284299
('mongoc_create_index_opts_t', Struct([
@@ -330,13 +345,15 @@ def __init__(self, items, **defaults):
330345
server_option,
331346
('batchSize', {'type': 'int32_t', 'help': 'An ``int32`` representing number of documents requested to be returned on each call to :symbol:`mongoc_cursor_next`', 'check_set': True}),
332347
let_option,
348+
comment_option_string_pre_4_4,
333349
])),
334350

335351
('mongoc_find_and_modify_appended_opts_t', Struct([
336352
write_concern_option,
337353
session_option,
338354
hint_option,
339355
let_option,
356+
comment_option_since_4_4,
340357
], opts_name='extra'))
341358
])
342359

src/libmongoc/doc/includes/aggregate-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
* ``serverId``: To target a specific server, include an int32 "serverId" field. Obtain the id by calling :symbol:`mongoc_client_select_server`, then :symbol:`mongoc_server_description_id` on its return value.
1414
* ``batchSize``: An ``int32`` representing number of documents requested to be returned on each call to :symbol:`mongoc_cursor_next`
1515
* ``let``: A BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language.
16+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Only string values are supported prior to MongoDB 4.4.

src/libmongoc/doc/includes/bulk-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
* ``ordered``: set to ``false`` to attempt to insert all documents, continuing after errors.
1010
* ``sessionId``: First, construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session`. You can begin a transaction with :symbol:`mongoc_client_session_start_transaction`, optionally with a :symbol:`mongoc_transaction_opt_t` that overrides the options inherited from |opts-source|, and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
1111
* ``let``: A BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language.
12+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.

src/libmongoc/doc/includes/change-stream-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
* ``startAtOperationTime``: A ``Timestamp``. The change stream only provides changes that occurred at or after the specified timestamp. Any command run against the server will return an operation time that can be used here. This option is mutually exclusive with ``resumeAfter`` and ``startAfter``.
1212
* ``maxAwaitTimeMS``: An ``int64`` representing the maximum amount of time a call to :symbol:`mongoc_change_stream_next` will block waiting for data
1313
* ``fullDocument``: A UTF-8 string. Set this option to "updateLookup" to direct the change stream cursor to lookup the most current majority-committed version of the document associated to an update change stream event.
14+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Only string values are supported prior to MongoDB 4.4.

src/libmongoc/doc/includes/delete-many-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* ``writeConcern``: Construct a :symbol:`mongoc_write_concern_t` and use :symbol:`mongoc_write_concern_append` to add the write concern to ``opts``. See the example code for :symbol:`mongoc_client_write_command_with_opts`.
99
* ``sessionId``: First, construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session`. You can begin a transaction with :symbol:`mongoc_client_session_start_transaction`, optionally with a :symbol:`mongoc_transaction_opt_t` that overrides the options inherited from |opts-source|, and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
1010
* ``validate``: Construct a bitwise-or of all desired :symbol:`bson_validate_flags_t <bson_validate_with_error>`. Set to ``false`` to skip client-side validation of the provided BSON documents.
11+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.
1112
* ``collation``: Configure textual comparisons. See :ref:`Setting Collation Order <setting_collation_order>`, and `the MongoDB Manual entry on Collation <https://docs.mongodb.com/manual/reference/collation/>`_. Collation requires MongoDB 3.2 or later, otherwise an error is returned.
1213
* ``hint``: A document or string that specifies the index to use to support the query predicate.
1314
* ``let``: A BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language.

src/libmongoc/doc/includes/delete-one-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* ``writeConcern``: Construct a :symbol:`mongoc_write_concern_t` and use :symbol:`mongoc_write_concern_append` to add the write concern to ``opts``. See the example code for :symbol:`mongoc_client_write_command_with_opts`.
99
* ``sessionId``: First, construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session`. You can begin a transaction with :symbol:`mongoc_client_session_start_transaction`, optionally with a :symbol:`mongoc_transaction_opt_t` that overrides the options inherited from |opts-source|, and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
1010
* ``validate``: Construct a bitwise-or of all desired :symbol:`bson_validate_flags_t <bson_validate_with_error>`. Set to ``false`` to skip client-side validation of the provided BSON documents.
11+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.
1112
* ``collation``: Configure textual comparisons. See :ref:`Setting Collation Order <setting_collation_order>`, and `the MongoDB Manual entry on Collation <https://docs.mongodb.com/manual/reference/collation/>`_. Collation requires MongoDB 3.2 or later, otherwise an error is returned.
1213
* ``hint``: A document or string that specifies the index to use to support the query predicate.
1314
* ``let``: A BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language.

src/libmongoc/doc/includes/find-and-modify-appended-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
* ``sessionId``: First, construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session`. You can begin a transaction with :symbol:`mongoc_client_session_start_transaction`, optionally with a :symbol:`mongoc_transaction_opt_t` that overrides the options inherited from |opts-source|, and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
1010
* ``hint``: A document or string that specifies the index to use to support the query predicate.
1111
* ``let``: A BSON document consisting of any number of parameter names, each followed by definitions of constants in the MQL Aggregate Expression language.
12+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.

src/libmongoc/doc/includes/insert-many-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
* ``writeConcern``: Construct a :symbol:`mongoc_write_concern_t` and use :symbol:`mongoc_write_concern_append` to add the write concern to ``opts``. See the example code for :symbol:`mongoc_client_write_command_with_opts`.
99
* ``sessionId``: First, construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session`. You can begin a transaction with :symbol:`mongoc_client_session_start_transaction`, optionally with a :symbol:`mongoc_transaction_opt_t` that overrides the options inherited from |opts-source|, and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
1010
* ``validate``: Construct a bitwise-or of all desired :symbol:`bson_validate_flags_t <bson_validate_with_error>`. Set to ``false`` to skip client-side validation of the provided BSON documents.
11+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.
1112
* ``ordered``: set to ``false`` to attempt to insert all documents, continuing after errors.
1213
* ``bypassDocumentValidation``: Set to ``true`` to skip server-side schema validation of the provided BSON documents.

src/libmongoc/doc/includes/insert-one-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
* ``writeConcern``: Construct a :symbol:`mongoc_write_concern_t` and use :symbol:`mongoc_write_concern_append` to add the write concern to ``opts``. See the example code for :symbol:`mongoc_client_write_command_with_opts`.
99
* ``sessionId``: First, construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session`. You can begin a transaction with :symbol:`mongoc_client_session_start_transaction`, optionally with a :symbol:`mongoc_transaction_opt_t` that overrides the options inherited from |opts-source|, and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
1010
* ``validate``: Construct a bitwise-or of all desired :symbol:`bson_validate_flags_t <bson_validate_with_error>`. Set to ``false`` to skip client-side validation of the provided BSON documents.
11+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.
1112
* ``bypassDocumentValidation``: Set to ``true`` to skip server-side schema validation of the provided BSON documents.

src/libmongoc/doc/includes/replace-one-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* ``writeConcern``: Construct a :symbol:`mongoc_write_concern_t` and use :symbol:`mongoc_write_concern_append` to add the write concern to ``opts``. See the example code for :symbol:`mongoc_client_write_command_with_opts`.
99
* ``sessionId``: First, construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session`. You can begin a transaction with :symbol:`mongoc_client_session_start_transaction`, optionally with a :symbol:`mongoc_transaction_opt_t` that overrides the options inherited from |opts-source|, and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
1010
* ``validate``: Construct a bitwise-or of all desired :symbol:`bson_validate_flags_t <bson_validate_with_error>`. Set to ``false`` to skip client-side validation of the provided BSON documents.
11+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.
1112
* ``bypassDocumentValidation``: Set to ``true`` to skip server-side schema validation of the provided BSON documents.
1213
* ``collation``: Configure textual comparisons. See :ref:`Setting Collation Order <setting_collation_order>`, and `the MongoDB Manual entry on Collation <https://docs.mongodb.com/manual/reference/collation/>`_. Collation requires MongoDB 3.2 or later, otherwise an error is returned.
1314
* ``hint``: A document or string that specifies the index to use to support the query predicate.

src/libmongoc/doc/includes/update-many-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* ``writeConcern``: Construct a :symbol:`mongoc_write_concern_t` and use :symbol:`mongoc_write_concern_append` to add the write concern to ``opts``. See the example code for :symbol:`mongoc_client_write_command_with_opts`.
99
* ``sessionId``: First, construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session`. You can begin a transaction with :symbol:`mongoc_client_session_start_transaction`, optionally with a :symbol:`mongoc_transaction_opt_t` that overrides the options inherited from |opts-source|, and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
1010
* ``validate``: Construct a bitwise-or of all desired :symbol:`bson_validate_flags_t <bson_validate_with_error>`. Set to ``false`` to skip client-side validation of the provided BSON documents.
11+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.
1112
* ``bypassDocumentValidation``: Set to ``true`` to skip server-side schema validation of the provided BSON documents.
1213
* ``collation``: Configure textual comparisons. See :ref:`Setting Collation Order <setting_collation_order>`, and `the MongoDB Manual entry on Collation <https://docs.mongodb.com/manual/reference/collation/>`_. Collation requires MongoDB 3.2 or later, otherwise an error is returned.
1314
* ``hint``: A document or string that specifies the index to use to support the query predicate.

src/libmongoc/doc/includes/update-one-opts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* ``writeConcern``: Construct a :symbol:`mongoc_write_concern_t` and use :symbol:`mongoc_write_concern_append` to add the write concern to ``opts``. See the example code for :symbol:`mongoc_client_write_command_with_opts`.
99
* ``sessionId``: First, construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session`. You can begin a transaction with :symbol:`mongoc_client_session_start_transaction`, optionally with a :symbol:`mongoc_transaction_opt_t` that overrides the options inherited from |opts-source|, and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
1010
* ``validate``: Construct a bitwise-or of all desired :symbol:`bson_validate_flags_t <bson_validate_with_error>`. Set to ``false`` to skip client-side validation of the provided BSON documents.
11+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.
1112
* ``bypassDocumentValidation``: Set to ``true`` to skip server-side schema validation of the provided BSON documents.
1213
* ``collation``: Configure textual comparisons. See :ref:`Setting Collation Order <setting_collation_order>`, and `the MongoDB Manual entry on Collation <https://docs.mongodb.com/manual/reference/collation/>`_. Collation requires MongoDB 3.2 or later, otherwise an error is returned.
1314
* ``hint``: A document or string that specifies the index to use to support the query predicate.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
:man_page: mongoc_bulk_operation_set_comment
2+
3+
mongoc_bulk_operation_set_comment()
4+
===================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void
12+
mongoc_bulk_operation_set_comment (
13+
mongoc_bulk_operation_t *bulk, const bson_value_t *comment);
14+
15+
Parameters
16+
----------
17+
18+
* ``bulk``: A :symbol:`mongoc_bulk_operation_t`.
19+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to associate with this bulk write.
20+
21+
Description
22+
-----------
23+
24+
Assigns a comment to attach to all commands executed as part of this :doc:`bulk <mongoc_bulk_operation_t>`. The comment will appear in log messages, profiler output, and currentOp output. Comments for write commands are only supported by MongoDB 4.4+.
25+
26+
It is prohibited to call this function after adding operations to the :doc:`bulk <mongoc_bulk_operation_t>`.

src/libmongoc/doc/mongoc_bulk_operation_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ After adding all of the write operations to the ``mongoc_bulk_operation_t``, cal
4949
mongoc_bulk_operation_replace_one_with_opts
5050
mongoc_bulk_operation_set_bypass_document_validation
5151
mongoc_bulk_operation_set_client_session
52+
mongoc_bulk_operation_set_comment
5253
mongoc_bulk_operation_set_hint
5354
mongoc_bulk_operation_set_let
5455
mongoc_bulk_operation_update

src/libmongoc/doc/mongoc_client_find_databases_with_opts.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Synopsis
1414
1515
Fetches a cursor containing documents, each corresponding to a database on this MongoDB server.
1616

17+
.. include:: includes/retryable-read.txt
18+
1719
Parameters
1820
----------
1921

@@ -24,7 +26,7 @@ Parameters
2426

2527
.. include:: includes/generic-opts.txt
2628

27-
.. include:: includes/retryable-read.txt
29+
For a list of all options, see `the MongoDB Manual entry on the listDatabases command <https://www.mongodb.com/docs/manual/reference/command/listDatabases/>`_.
2830

2931
Errors
3032
------

src/libmongoc/doc/mongoc_client_get_database_names_with_opts.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Synopsis
1616
1717
This function queries the MongoDB server for a list of known databases.
1818

19+
.. include:: includes/retryable-read.txt
20+
1921
Parameters
2022
----------
2123

@@ -27,7 +29,7 @@ Parameters
2729

2830
.. include:: includes/generic-opts.txt
2931

30-
.. include:: includes/retryable-read.txt
32+
For a list of all options, see `the MongoDB Manual entry on the listDatabases command <https://www.mongodb.com/docs/manual/reference/command/listDatabases/>`_.
3133

3234
Errors
3335
------

src/libmongoc/doc/mongoc_collection_count_documents.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Parameters
3131
.. include:: includes/read-opts.txt
3232
* ``skip``: An int specifying how many documents matching the ``query`` should be skipped before counting.
3333
* ``limit``: An int specifying the maximum number of documents to count.
34+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Specifying a non-string value requires MongoDB 4.4 or later.
3435

3536
Description
3637
-----------

src/libmongoc/doc/mongoc_collection_estimated_document_count.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Parameters
2929
.. include:: includes/read-opts.txt
3030
* ``skip``: An int specifying how many documents matching the ``query`` should be skipped before counting.
3131
* ``limit``: An int specifying the maximum number of documents to count.
32+
* ``comment``: A :symbol:`bson_value_t` specifying the comment to attach to this command. The comment will appear in log messages, profiler output, and currentOp output. Requires MongoDB 4.4 or later.
33+
34+
For a list of all options, see `the MongoDB Manual entry on the count command <https://www.mongodb.com/docs/manual/reference/command/count/>`_.
3235

3336
Description
3437
-----------

0 commit comments

Comments
 (0)