-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for docs-php-library ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format LGTM!
There was a problem hiding this 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?
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline at EOF.
// end-update-for-change-stream | |
// end-update-for-change-stream | |
do { | ||
$changeStream->next(); | ||
|
||
if ($changeStream->valid()) { | ||
$event = $changeStream->current(); | ||
echo toJSON($event), PHP_EOL; | ||
} | ||
} while (! $changeStream->valid() || $changeStream->current()['operationType'] !== 'invalidate'); |
There was a problem hiding this comment.
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:
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; | |
} | |
} |
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-43912
Staging Links
Self-Review Checklist