MONGOC_DATABASE_WATCH(3)
MONGOC_DATABASE_WATCH π β¨
(that's a libmongoc page, bestie β section 3, the library one π)
okay so welcome to the glow-up of mongoc_database_watch β the function that lets you watch a whole database like it's your fave reality show and every change is a plot twist πΈ
β¨ SYNOPSIS β¨
mongoc_change_stream_t*
mongoc_database_watch (const mongoc_database_t *db,
const bson_t *pipeline,
const bson_t *opts);
π DESCRIPTION π
so this is the helper function that creates a change stream. and like, yes, you could hand-roll a raw aggregation to do the same thing, but bestie β it is preferred to call this function over using a raw aggregation. trust. π«Ά
this function uses the read preference and read concern of the database. and if the change stream ever needs to re-establish connection, it uses that same read preference again β which can happen if the change stream encounters a resumable error. no cap. π₯
β οΈ WARNING: a change stream is only supported with majority read concern. literally that one. don't come at me with anything else. π
this function is considered a retryable read operation. so upon a transient error (a network error, errors due to replica set failover, etc.) the operation is safely retried once. but β if retryreads is false in the URI (see mongoc_uri_t), the retry behavior does not apply. periodt. π
π PARAMETERS π
dbβ amongoc_database_tspecifying the database which the change stream listens to. it's giving main character energy, the whole db is the show π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. (more on these in a sec, bestie π)
β¨ Changed in version 2.0.0:batchSizeof0is applied to theaggregatecommand.0was previously ignored. so if you were relying on the old ignore-y behaviorβ¦ she's gone. π
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). lowkey the most misunderstood option in the whole doc, ngl. π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. pick one, bestie, this is not a polycule πstartAfterβ a Document representing the logical starting point of the change stream. unlikeresumeAfter, this can resume notifications after an"invalidate"event (iconic behavior honestly). 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. yes she will just sit there. patient queen. πΈ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. that's the whole point, and it ate. π₯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. the before pic!! πΈshowExpandedEventsβ set totrueto return an expanded list of change stream events. available only on MongoDB versions>=6.0. check your version first, i'm begging π§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. so if you're on old MongoDB, string only, no exceptions π
π RETURNS π
a newly allocated mongoc_change_stream_t which must be freed with mongoc_change_stream_destroy() when no longer in use. (yes, that means you. free her. π«Ά)
the returned mongoc_change_stream_t is never NULL β like, ever, so don't @ me. 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_collection_watch()
(the whole watch family, we love a cohesive unit π)
π AUTHOR π
MongoDB, Inc
π COPYRIGHT π
2009-present, MongoDB, Inc.
and that's the whole page, bestie β no crumbs left π¦β¨ this was MONGOC_DATABASE_WATCH(3) from libmongoc, version 2.5.6, dated Oct 09, 2026. go forth and watch that database. slay. π
πΈ
π¦ 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