Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCSP-43081: Change Streams #37

Merged
merged 4 commits into from
Sep 18, 2024

Conversation

mcmorisi
Copy link
Collaborator

@mcmorisi mcmorisi commented Sep 16, 2024

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

  • Is this free of any warnings or errors in the RST?
  • Did you run a spell-check?
  • Did you run a grammar-check?
  • Are all the links working?
  • Are the facets and meta keywords accurate?

@mcmorisi mcmorisi changed the base branch from master to standardization September 16, 2024 20:04
Copy link

netlify bot commented Sep 16, 2024

Deploy Preview for docs-c ready!

Name Link
🔨 Latest commit 067c814
🔍 Latest deploy log https://app.netlify.com/sites/docs-c/deploys/66eb36409aab69000801b523
😎 Deploy Preview https://deploy-preview-37--docs-c.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@jordan-smith721 jordan-smith721 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: Change to data since you can open a change stream on more than just a database

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
scope of events you want to observe.
scope of events you want to observe:

Comment on lines 42 to 44
- ``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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- ``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

Comment on lines 101 to 102
change events. Format the parameter as a list of objects that each represents an
aggregation stage.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S:

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to open a change stream that only records update operations:
to open a change stream that records only update operations:

@mcmorisi mcmorisi marked this pull request as ready for review September 17, 2024 16:54
Copy link
Collaborator

@jordan-smith721 jordan-smith721 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@mcmorisi mcmorisi requested a review from kevinAlbs September 17, 2024 18:34
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
  }
}

@mcmorisi mcmorisi merged commit a661697 into mongodb:standardization Sep 18, 2024
4 of 5 checks passed
@mcmorisi mcmorisi deleted the DOCSP-43081-change-streams branch September 18, 2024 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants