MONGOC_COLLECTION_WATCH(3)
π MONGOC_COLLECTION_WATCH(3) π
okay bestie, welcome to the libmongoc manual page for mongoc_collection_watch(3). This helper ate and left no crumbs: it's the one that creates a change stream, and ngl, it's giving "why would you do a raw aggregation when this exists?" energy. π«Ά
β¨ SYNOPSIS β¨
mongoc_change_stream_t*
mongoc_collection_watch (const mongoc_collection_t *coll,
const bson_t *pipeline,
const bson_t *opts);
πΈ DESCRIPTION πΈ
This is a helper function to create a change stream. It is preferred to call this function over using a raw aggregation to create a change stream. No cap.
This function uses the read preference and read concern of the collection. If the change stream needs to re-establish connection, the same read preference will be used. This may happen if the change stream encounters a resumable error.
β οΈ WARNING: A change stream is only supported with majority read concern. That's the whole vibe check, bestie β majority read concern only, periodt. π
This function is considered a retryable read operation. Upon a transient error (a network error, errors due to replica set failover, etc.) the operation is safely retried once. If retryreads is false in the URI (see mongoc_uri_t) the retry behavior does not apply.
π PARAMETERS π
collβ Amongoc_collection_tspecifying the collection which the change stream listens to.pipelineβ Abson_trepresenting an aggregation pipeline appended to the change stream. This may be an empty document.optsβ Abson_tcontaining change stream options.
Changed in version 2.0.0: batchSize of 0 is applied to the aggregate command. 0 was previously ignored.
opts may be NULL or a BSON document with additional command options:
batchSizeβ Anint32requesting a limit of documents returned in each server reply. If positive, thebatchSizeis applied to bothaggregateandgetMorecommands. If0, thebatchSizeis only applied to theaggregatecommand (useful to request an immediate cursor without significant server-side work. See Aggregate Data Specifying Batch Size). If 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 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β Anint64representing 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. 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_client_watch()mongoc_database_watch()
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
π that's the whole page, bestie! π This was MONGOC_COLLECTION_WATCH(3) from libmongoc version 2.5.6, dated Oct 09, 2026. Slay, and remember: change streams are main character energy. π
β¨
π¦ 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