DOCSP-43081: Change Streams - #37
Conversation
✅ Deploy Preview for docs-c ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
jordan-smith721
left a comment
There was a problem hiding this comment.
Nice job! Just a few changes
| -------- | ||
|
|
||
| In this guide, you can learn how to use the {+driver-short+} to monitor a **change stream**, | ||
| allowing you to view real-time changes to your database. A change stream is a {+mdb-server+} feature that |
There was a problem hiding this comment.
S: Change to data since you can open a change stream on more than just a database
| allowing you to view real-time changes to your database. A change stream is a {+mdb-server+} feature that | |
| allowing you to view real-time changes to your data. A change stream is a {+mdb-server+} feature that |
| -------------------- | ||
|
|
||
| To open a change stream, call one of the following functions that corresponds to the | ||
| scope of events you want to observe. |
There was a problem hiding this comment.
| scope of events you want to observe. | |
| scope of events you want to observe: |
| - ``mongoc_client_watch()``: To monitor all changes in the MongoDB deployment | ||
| - ``mongoc_database_watch()``: To monitor changes in all collections in the database | ||
| - ``mongoc_collection_watch()``: To monitor changes in the collection |
There was a problem hiding this comment.
| - ``mongoc_client_watch()``: To monitor all changes in the MongoDB deployment | |
| - ``mongoc_database_watch()``: To monitor changes in all collections in the database | |
| - ``mongoc_collection_watch()``: To monitor changes in the collection | |
| - ``mongoc_client_watch()``: Monitors all changes in the MongoDB deployment | |
| - ``mongoc_database_watch()``: Monitors changes in all collections in the database | |
| - ``mongoc_collection_watch()``: Monitors changes in the collection |
| change events. Format the parameter as a list of objects that each represents an | ||
| aggregation stage. |
There was a problem hiding this comment.
S:
| change events. Format the parameter as a list of objects that each represents an | |
| aggregation stage. | |
| change events. Format the parameter as a list of objects, where each object represents an | |
| aggregation stage. |
| - ``$set`` | ||
| - ``$unset`` | ||
|
|
||
| Match Specific events Example |
There was a problem hiding this comment.
| Match Specific events Example | |
| Match Specific Events Example |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| The following example uses the ``pipeline`` parameter to include a ``$match`` stage | ||
| to open a change stream that only records update operations: |
There was a problem hiding this comment.
| to open a change stream that only records update operations: | |
| to open a change stream that records only update operations: |
jordan-smith721
left a comment
There was a problem hiding this comment.
LGTM w a small fix!
|
|
||
| You can pass the ``pipeline`` parameter to any watch function to modify the | ||
| change stream output. This parameter allows you to watch for only specified | ||
| change events. Format the parameter as a list of object, where each object represents an |
There was a problem hiding this comment.
| change events. Format the parameter as a list of object, where each object represents an | |
| change events. Format the parameter as a list of objects, where each object represents an |
kevinAlbs
left a comment
There was a problem hiding this comment.
LGTM as-is, but added a comment to consider an alternative looping.
| mongoc_change_stream_t *change_stream = | ||
| mongoc_collection_watch (collection, pipeline, opts); | ||
|
|
||
| while (mongoc_change_stream_next (change_stream, &doc)) { |
There was a problem hiding this comment.
mongoc_change_stream_next only returns true when a change is returned within the maxAwaitTimeMS. If no change was returned, and no error occurred, a later call to mongoc_change_stream_next can still return a change.
If the examples are intended to show the behavior of "wait (possibly forever) until there is an event or error", then I suggest looping as follows:
while (true)
{
bson_error_t error;
if (mongoc_change_stream_next(change_stream, &doc))
{
char *str = bson_as_canonical_extended_json(doc, NULL);
printf("Received change: %s\n", str);
bson_free(str);
}
else if (mongoc_change_stream_error_document(change_stream, &error, NULL))
{
printf("Got error on change stream: %s\n", error.message);
break;
}
}
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-43081
Staging - https://deploy-preview-37--docs-c.netlify.app/read/change-streams
Self-Review Checklist