MONGOC_CLIENT_WATCH(3)
π MONGOC_CLIENT_WATCH π
okay bestie, this is the libmongoc page for mongoc_client_watch β literally the glow-up shortcut for making a change stream β¨
πΈ SYNOPSIS πΈ
mongoc_change_stream_t*
mongoc_client_watch (mongoc_client_t *client,
const bson_t *pipeline,
const bson_t *opts);
π¦ DESCRIPTION π¦
So this is a little helper function that spins up a change stream for you π and honestly? Use this instead of hand-rolling a raw aggregation to make a change stream. It's the preferred way, no cap. It's giving "let the library carry the bags."
It uses the read preference and read concern of the client β and if the change stream ever needs to re-establish its connection, it'll use that same read preference again. That reconnecting situation can pop off if the change stream runs into a resumable error. π
β οΈ WARNING: a change stream is only supported with majority read concern. That's the vibe check it has to pass, periodt.
This function is considered a retryable read operation. On a transient error (a network error, errors from replica set failover, etc. etc.) the operation gets safely retried once. But if retryreads is false in the URI (peep mongoc_uri_t), then the retry behavior does not apply. π
β¨ PARAMETERS β¨
dbβ amongoc_client_tspecifying the client which the change stream listens to. πpipelineβ abson_trepresenting an aggregation pipeline appended to the change stream. It may be an empty document, so no pressure. πoptsβ abson_tcontaining change stream options.
π Changed in version 2.0.0:batchSizeof0is applied to theaggregatecommand.0was previously ignored. (iconic behavior change, honestly)
opts may be NULL or a BSON document with additional command options:
batchSizeβ an int32 requesting a limit of documents returned in each server reply. If it's positive, thebatchSizeis applied to bothaggregateandgetMorecommands. If it's0, thebatchSizeis only applied to theaggregatecommand (useful to request an immediate cursor without significant server-side work β see Aggregate Data Specifying Batch Size). If it's omitted or negative, the value is ignored and server defaults are used (see Cursor Batches for a description of server defaults). πresumeAfterβ a Document representing the logical starting point of the change stream. The result ofmongoc_change_stream_get_resume_token()or the_idfield of any change received from a change stream can be used here. This option is mutually exclusive withstartAfterandstartAtOperationTime. π«startAfterβ a Document representing the logical starting point of the change stream. UnlikeresumeAfter, this one can resume notifications after an"invalidate"event. The result ofmongoc_change_stream_get_resume_token()or the_idfield of any change received from a change stream can be used here. This option is mutually exclusive withresumeAfterandstartAtOperationTime. π₯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 withresumeAfterandstartAfter. βmaxAwaitTimeMSβ an int64 representing the maximum amount of time a call tomongoc_change_stream_next()will block waiting for data.fullDocumentβ an optional UTF-8 string. Set this option to"default","updateLookup","whenAvailable", or"required". If unset, the string"default"is assumed. 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. πfullDocumentBeforeChangeβ an optional UTF-8 string. Set this option to"whenAvailable","required", or"off". When unset, the default value is"off". Similar to"fullDocument", but returns the value of the document before the associated change. π°οΈshowExpandedEventsβ set totrueto return an expanded list of change stream events. Available only on MongoDB versions>=6.0. πcommentβ abson_value_tspecifying the comment to attach to this command. The comment will appear in log messages, profiler output, andcurrentOpoutput. Only string values are supported prior to MongoDB4.4. π
π RETURNS π
A newly allocated mongoc_change_stream_t which must be freed with mongoc_change_stream_destroy() when no longer in use. The returned mongoc_change_stream_t is never NULL β yes bestie, never, we love a guaranteed pointer. π If there is an error, it can be retrieved with mongoc_change_stream_error_document(), and subsequent calls to mongoc_change_stream_next() will return false.
π SEE ALSO π
mongoc_database_watch()mongoc_collection_watch()
π«Ά AUTHOR π«Ά
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
and that's the whole page, bestie β libmongoc version 2.5.6, dated Oct 09, 2026, signed off with love π go forth and watch those changes π¦β¨
π¦ where this page comes from
- epel 10: mongo-c-driver-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms