Skip to content

DOCSP-43912: Improve change stream code examples #264

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mcmorisi
Copy link
Collaborator

@mcmorisi mcmorisi commented Jun 4, 2025

Pull Request Info

PR Reviewing Guidelines

JIRA - https://jira.mongodb.org/browse/DOCSP-43912

Staging Links

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?

Copy link

netlify bot commented Jun 4, 2025

Deploy Preview for docs-php-library ready!

Name Link
🔨 Latest commit 12588df
🔍 Latest deploy log https://app.netlify.com/projects/docs-php-library/deploys/6848390202608c0008770dd6
😎 Deploy Preview https://deploy-preview-264--docs-php-library.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 project configuration.

Copy link
Collaborator

@lindseymoore lindseymoore left a comment

Choose a reason for hiding this comment

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

Format LGTM!

@mcmorisi mcmorisi requested a review from GromNaN June 4, 2025 18:37
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

The change-streams.php cannot be run on its own as each change stream loop is an infinite loop (unless you drop the collection). Wouldn't is better to create separate files that we can run?

@mcmorisi mcmorisi requested a review from GromNaN June 10, 2025 13:59
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

I'm not convinced by the new style. Keeping the previous for loop, or replacing with a while(true) would be more comprehensible.

['name' => 'Blarney Castle'],
['$set' => ['cuisine' => 'Irish']]
);
// end-update-for-change-stream
Copy link
Member

Choose a reason for hiding this comment

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

Missing newline at EOF.

Suggested change
// end-update-for-change-stream
// end-update-for-change-stream

Comment on lines +24 to +31
do {
$changeStream->next();

if ($changeStream->valid()) {
$event = $changeStream->current();
echo toJSON($event), PHP_EOL;
}
} while (! $changeStream->valid() || $changeStream->current()['operationType'] !== 'invalidate');
Copy link
Member

Choose a reason for hiding this comment

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

On reflection, this notation is much more complex than the previous example.

In my original comment the idea was rather to use while(true) like this:

Suggested change
do {
$changeStream->next();
if ($changeStream->valid()) {
$event = $changeStream->current();
echo toJSON($event), PHP_EOL;
}
} while (! $changeStream->valid() || $changeStream->current()['operationType'] !== 'invalidate');
while (true) {
$changeStream->next();
if (! $changeStream->valid()) {
continue;
}
$event = $changeStream->current();
echo toJSON($event), PHP_EOL;
if ($changeStream->current()['operationType'] === 'invalidate') {
break;
}
}

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