Skip to content

Commit 8c3f249

Browse files
committed
Comment option for findAndModify, aggregate, and change streams
1 parent 60fef92 commit 8c3f249

File tree

8 files changed

+50
-0
lines changed

8 files changed

+50
-0
lines changed

build/generate-opts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def __init__(self, items, **defaults):
287287
('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``.'}),
288288
('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'}),
289289
('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.'}),
290+
comment_option,
290291
], fullDocument="default")),
291292

292293
('mongoc_create_index_opts_t', Struct([
@@ -338,13 +339,15 @@ def __init__(self, items, **defaults):
338339
server_option,
339340
('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}),
340341
let_option,
342+
comment_option,
341343
])),
342344

343345
('mongoc_find_and_modify_appended_opts_t', Struct([
344346
write_concern_option,
345347
session_option,
346348
hint_option,
347349
let_option,
350+
comment_option,
348351
], opts_name='extra'))
349352
])
350353

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``: Comment to attach to this command, which will appear in log messages, profiler output, and currentOp output.

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``: Comment to attach to this command, which will appear in log messages, profiler output, and currentOp output.

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``: Comment to attach to this command, which will appear in log messages, profiler output, and currentOp output.

src/libmongoc/src/mongoc/mongoc-change-stream.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ _make_cursor (mongoc_change_stream_t *stream)
243243
bson_init (&command);
244244
bson_copy_to (&(stream->opts.extra), &command_opts);
245245

246+
if (stream->opts.comment.value_type != BSON_TYPE_EOD) {
247+
bson_append_value (&command_opts, "comment", 7, &stream->opts.comment);
248+
}
249+
246250
if (bson_iter_init_find (&iter, &command_opts, "sessionId")) {
247251
if (!_mongoc_client_session_from_iter (
248252
stream->client, &iter, &cs, &stream->err)) {

src/libmongoc/src/mongoc/mongoc-collection.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,10 @@ mongoc_collection_find_and_modify_with_opts (
34513451
bson_append_document (&parts.extra, "let", 3, &appended_opts.let);
34523452
}
34533453

3454+
if (&appended_opts.comment.value_type != BSON_TYPE_EOD) {
3455+
bson_append_value (&parts.extra, "comment", 7, &appended_opts.comment);
3456+
}
3457+
34543458
/* Append any remaining unparsed options set via
34553459
* mongoc_find_and_modify_opts_append to the command part. */
34563460
if (bson_iter_init (&iter, &appended_opts.extra)) {

src/libmongoc/src/mongoc/mongoc-opts-private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ typedef struct _mongoc_change_stream_opts_t {
145145
mongoc_timestamp_t startAtOperationTime;
146146
int64_t maxAwaitTimeMS;
147147
const char *fullDocument;
148+
bson_value_t comment;
148149
bson_t extra;
149150
} mongoc_change_stream_opts_t;
150151

@@ -191,6 +192,7 @@ typedef struct _mongoc_aggregate_opts_t {
191192
int32_t batchSize;
192193
bool batchSize_is_set;
193194
bson_t let;
195+
bson_value_t comment;
194196
bson_t extra;
195197
} mongoc_aggregate_opts_t;
196198

@@ -200,6 +202,7 @@ typedef struct _mongoc_find_and_modify_appended_opts_t {
200202
mongoc_client_session_t *client_session;
201203
bson_value_t hint;
202204
bson_t let;
205+
bson_value_t comment;
203206
bson_t extra;
204207
} mongoc_find_and_modify_appended_opts_t;
205208

src/libmongoc/src/mongoc/mongoc-opts.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,7 @@ _mongoc_change_stream_opts_parse (
15821582
memset (&mongoc_change_stream_opts->startAtOperationTime, 0, sizeof (mongoc_timestamp_t));
15831583
mongoc_change_stream_opts->maxAwaitTimeMS = 0;
15841584
mongoc_change_stream_opts->fullDocument = "default";
1585+
memset (&mongoc_change_stream_opts->comment, 0, sizeof (bson_value_t));
15851586
bson_init (&mongoc_change_stream_opts->extra);
15861587

15871588
if (!opts) {
@@ -1651,6 +1652,15 @@ _mongoc_change_stream_opts_parse (
16511652
return false;
16521653
}
16531654
}
1655+
else if (!strcmp (bson_iter_key (&iter), "comment")) {
1656+
if (!_mongoc_convert_bson_value_t (
1657+
client,
1658+
&iter,
1659+
&mongoc_change_stream_opts->comment,
1660+
error)) {
1661+
return false;
1662+
}
1663+
}
16541664
else {
16551665
/* unrecognized values are copied to "extra" */
16561666
if (!BSON_APPEND_VALUE (
@@ -1674,6 +1684,7 @@ _mongoc_change_stream_opts_cleanup (mongoc_change_stream_opts_t *mongoc_change_s
16741684
{
16751685
bson_destroy (&mongoc_change_stream_opts->resumeAfter);
16761686
bson_destroy (&mongoc_change_stream_opts->startAfter);
1687+
bson_value_destroy (&mongoc_change_stream_opts->comment);
16771688
bson_destroy (&mongoc_change_stream_opts->extra);
16781689
}
16791690

@@ -2040,6 +2051,7 @@ _mongoc_aggregate_opts_parse (
20402051
mongoc_aggregate_opts->batchSize = 0;
20412052
mongoc_aggregate_opts->batchSize_is_set = false;
20422053
bson_init (&mongoc_aggregate_opts->let);
2054+
memset (&mongoc_aggregate_opts->comment, 0, sizeof (bson_value_t));
20432055
bson_init (&mongoc_aggregate_opts->extra);
20442056

20452057
if (!opts) {
@@ -2131,6 +2143,15 @@ _mongoc_aggregate_opts_parse (
21312143
return false;
21322144
}
21332145
}
2146+
else if (!strcmp (bson_iter_key (&iter), "comment")) {
2147+
if (!_mongoc_convert_bson_value_t (
2148+
client,
2149+
&iter,
2150+
&mongoc_aggregate_opts->comment,
2151+
error)) {
2152+
return false;
2153+
}
2154+
}
21342155
else {
21352156
/* unrecognized values are copied to "extra" */
21362157
if (!BSON_APPEND_VALUE (
@@ -2158,6 +2179,7 @@ _mongoc_aggregate_opts_cleanup (mongoc_aggregate_opts_t *mongoc_aggregate_opts)
21582179
}
21592180
bson_destroy (&mongoc_aggregate_opts->collation);
21602181
bson_destroy (&mongoc_aggregate_opts->let);
2182+
bson_value_destroy (&mongoc_aggregate_opts->comment);
21612183
bson_destroy (&mongoc_aggregate_opts->extra);
21622184
}
21632185

@@ -2175,6 +2197,7 @@ _mongoc_find_and_modify_appended_opts_parse (
21752197
mongoc_find_and_modify_appended_opts->client_session = NULL;
21762198
memset (&mongoc_find_and_modify_appended_opts->hint, 0, sizeof (bson_value_t));
21772199
bson_init (&mongoc_find_and_modify_appended_opts->let);
2200+
memset (&mongoc_find_and_modify_appended_opts->comment, 0, sizeof (bson_value_t));
21782201
bson_init (&mongoc_find_and_modify_appended_opts->extra);
21792202

21802203
if (!opts) {
@@ -2228,6 +2251,15 @@ _mongoc_find_and_modify_appended_opts_parse (
22282251
return false;
22292252
}
22302253
}
2254+
else if (!strcmp (bson_iter_key (&iter), "comment")) {
2255+
if (!_mongoc_convert_bson_value_t (
2256+
client,
2257+
&iter,
2258+
&mongoc_find_and_modify_appended_opts->comment,
2259+
error)) {
2260+
return false;
2261+
}
2262+
}
22312263
else {
22322264
/* unrecognized values are copied to "extra" */
22332265
if (!BSON_APPEND_VALUE (
@@ -2254,5 +2286,6 @@ _mongoc_find_and_modify_appended_opts_cleanup (mongoc_find_and_modify_appended_o
22542286
}
22552287
bson_value_destroy (&mongoc_find_and_modify_appended_opts->hint);
22562288
bson_destroy (&mongoc_find_and_modify_appended_opts->let);
2289+
bson_value_destroy (&mongoc_find_and_modify_appended_opts->comment);
22572290
bson_destroy (&mongoc_find_and_modify_appended_opts->extra);
22582291
}

0 commit comments

Comments
 (0)