Skip to content

Commit 8bc2fd7

Browse files
CDRIVER-4305: 'fullDocument' may be null/omitted (#1010)
This commit implements CDRIVER-4305, which allows fullDocument to be NULL equivalent to a literal "default" string. This is permitted in server 3.6+, and this change makes that the preferred and default behavior. This driver already requires 3.6 or newer (as per minWireVersion)
1 parent 2006bc1 commit 8bc2fd7

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ _make_command (mongoc_change_stream_t *stream, bson_t *command)
123123
bson_append_document_begin (&pipeline, "0", 1, &change_stream_stage);
124124
bson_append_document_begin (
125125
&change_stream_stage, "$changeStream", 13, &change_stream_doc);
126-
bson_concat (&change_stream_doc, stream->full_document);
126+
if (stream->full_document) {
127+
bson_concat (&change_stream_doc, stream->full_document);
128+
}
127129

128130
if (stream->resumed) {
129131
/* Change stream spec: Resume Process */
@@ -412,7 +414,12 @@ _change_stream_init (mongoc_change_stream_t *stream,
412414
return;
413415
}
414416

415-
stream->full_document = BCON_NEW ("fullDocument", stream->opts.fullDocument);
417+
if (stream->opts.fullDocument) {
418+
stream->full_document =
419+
BCON_NEW ("fullDocument", stream->opts.fullDocument);
420+
} else {
421+
stream->full_document = NULL;
422+
}
416423

417424
_mongoc_timestamp_set (&stream->operation_time,
418425
&stream->opts.startAtOperationTime);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ _mongoc_change_stream_opts_parse (
15811581
bson_init (&mongoc_change_stream_opts->startAfter);
15821582
memset (&mongoc_change_stream_opts->startAtOperationTime, 0, sizeof (mongoc_timestamp_t));
15831583
mongoc_change_stream_opts->maxAwaitTimeMS = 0;
1584-
mongoc_change_stream_opts->fullDocument = "default";
1584+
mongoc_change_stream_opts->fullDocument = NULL;
15851585
memset (&mongoc_change_stream_opts->comment, 0, sizeof (bson_value_t));
15861586
bson_init (&mongoc_change_stream_opts->extra);
15871587

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ test_change_stream_pipeline (void)
130130
MONGOC_MSG_NONE,
131131
tmp_bson ("{'$db': 'db',"
132132
" 'aggregate': 'coll',"
133-
" 'pipeline': [{'$changeStream': {'fullDocument': 'default'}}],"
133+
" 'pipeline': [{'$changeStream': {}}],"
134134
" 'cursor': {}}"));
135135

136136
mock_server_replies_simple (
@@ -180,15 +180,15 @@ test_change_stream_pipeline (void)
180180
/* Test non-empty pipeline */
181181
future = future_collection_watch (coll, nonempty_pipeline, NULL);
182182

183-
request = mock_server_receives_msg (
184-
server,
185-
MONGOC_MSG_NONE,
186-
tmp_bson ("{'$db': 'db',"
187-
" 'aggregate': 'coll',"
188-
" 'pipeline': ["
189-
" {'$changeStream': {'fullDocument': 'default'}},"
190-
" {'$project': {'ns': false}}],"
191-
" 'cursor': {}}"));
183+
request =
184+
mock_server_receives_msg (server,
185+
MONGOC_MSG_NONE,
186+
tmp_bson ("{'$db': 'db',"
187+
" 'aggregate': 'coll',"
188+
" 'pipeline': ["
189+
" {'$changeStream': {}},"
190+
" {'$project': {'ns': false}}],"
191+
" 'cursor': {}}"));
192192
mock_server_replies_simple (
193193
request,
194194
"{'cursor': {'id': 123, 'ns': 'db.coll','firstBatch': []},'ok': 1}");
@@ -739,11 +739,10 @@ test_change_stream_resumable_error (void)
739739
"{ 'code': 10107, 'errmsg': 'not primary', 'ok': 0 }";
740740
const char *interrupted_err =
741741
"{ 'code': 11601, 'errmsg': 'interrupted', 'ok': 0 }";
742-
const bson_t *watch_cmd =
743-
tmp_bson ("{'$db': 'db',"
744-
" 'aggregate': 'coll',"
745-
" 'pipeline': [{'$changeStream': {'fullDocument': 'default'}}],"
746-
" 'cursor': {}}");
742+
const bson_t *watch_cmd = tmp_bson ("{'$db': 'db',"
743+
" 'aggregate': 'coll',"
744+
" 'pipeline': [{'$changeStream': {}}],"
745+
" 'cursor': {}}");
747746
const char *expected_msg =
748747
"{'$db': 'db', 'getMore': {'$numberLong': '%d'}, 'collection': 'coll' }";
749748

@@ -1825,7 +1824,7 @@ _test_resume (const char *opts,
18251824
server,
18261825
MONGOC_QUERY_NONE,
18271826
tmp_bson ("{ 'aggregate': 'coll', 'pipeline' : [ { '$changeStream': { %s "
1828-
"'fullDocument': 'default' } } ], 'cursor': { } }",
1827+
" 'fullDocument': null } } ], 'cursor': { } }",
18291828
expected_change_stream_opts));
18301829
msg = bson_strdup_printf ("{'cursor': {'id': 123, 'ns': 'db.coll',"
18311830
"'firstBatch': [%s]%s }, 'operationTime': "
@@ -1855,7 +1854,7 @@ _test_resume (const char *opts,
18551854
server,
18561855
MONGOC_QUERY_NONE,
18571856
tmp_bson ("{ 'aggregate': 'coll', 'pipeline' : [ { '$changeStream': { %s "
1858-
"'fullDocument': 'default' }} ], 'cursor': { } }",
1857+
" 'fullDocument': null }} ], 'cursor': { } }",
18591858
expected_resume_change_stream_opts));
18601859
mock_server_replies_simple (
18611860
request,

0 commit comments

Comments
 (0)