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-45200: Change streams #123

Merged

Conversation

norareidy
Copy link
Collaborator

@norareidy norareidy commented Jan 9, 2025

Pull Request Info

PR Reviewing Guidelines

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

Staging Links

  • read/change-streams
  • read
  • 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?

    Copy link

    netlify bot commented Jan 9, 2025

    Deploy Preview for docs-ruby ready!

    Name Link
    🔨 Latest commit 7b68ed7
    🔍 Latest deploy log https://app.netlify.com/sites/docs-ruby/deploys/678aa50389ea930008f03e94
    😎 Deploy Preview https://deploy-preview-123--docs-ruby.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
    Contributor

    @rachel-mack rachel-mack left a comment

    Choose a reason for hiding this comment

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

    LGTM

    @norareidy norareidy requested a review from jamis January 9, 2025 18:38
    Comment on lines 20 to 24
    enum = stream.to_enum
    while (doc = enum.next)
    puts doc
    break if doc['operationType'] == 'invalidate'
    end
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Using stream#each will be simpler, and more idiomatic:

    Suggested change
    enum = stream.to_enum
    while (doc = enum.next)
    puts doc
    break if doc['operationType'] == 'invalidate'
    end
    stream.each do |doc|
    puts doc
    break if doc['operationType'] == 'invalidate'
    end

    Comment on lines 39 to 43
    enum = stream.to_enum
    while (doc = enum.next)
    puts doc
    break if doc['operationType'] == 'invalidate'
    end
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Explicitly converting the stream to an enum is usually a hint that you're doing something the hard way. Prefer stream#each when iterating over a stream:

    Suggested change
    enum = stream.to_enum
    while (doc = enum.next)
    puts doc
    break if doc['operationType'] == 'invalidate'
    end
    stream.each do |doc|
    puts doc
    break if doc['operationType'] == 'invalidate'
    end

    Comment on lines 50 to 54
    enum = stream.to_enum
    while (doc = enum.next)
    puts doc
    break if doc['operationType'] == 'invalidate'
    end
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Suggested change
    enum = stream.to_enum
    while (doc = enum.next)
    puts doc
    break if doc['operationType'] == 'invalidate'
    end
    stream.each do |doc|
    puts doc
    break if doc['operationType'] == 'invalidate'
    end

    Comment on lines 28 to 31
    When using the {+driver-short+}, you can call the ``watch`` method to return a
    ``Mongo::Collection::View::ChangeStream`` object. Then, you can convert the change
    stream to an ``Enumerator`` object and iterate through its content to monitor data
    changes, such as updates, insertions, and deletions.
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    There's no need to convert the change stream to an enumerator, as the stream is already iterable. Maybe something like the following?

    Suggested change
    When using the {+driver-short+}, you can call the ``watch`` method to return a
    ``Mongo::Collection::View::ChangeStream`` object. Then, you can convert the change
    stream to an ``Enumerator`` object and iterate through its content to monitor data
    changes, such as updates, insertions, and deletions.
    When using the {+driver-short+}, you can call the ``watch`` method to return a
    ``Mongo::Collection::View::ChangeStream`` object. Then, you can iterate through
    its content to monitor data changes, such as updates, insertions, and deletions.

    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    I like this wording, updated! Sorry about that confusion

    Comment on lines 64 to 65
    The following example opens a change stream on the ``restaurants`` collection,
    converts the change stream to an ``Enumerator``, and outputs changes as they occur:
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    As mentioned, there's no need to convert the stream to an enumerator.

    Suggested change
    The following example opens a change stream on the ``restaurants`` collection,
    converts the change stream to an ``Enumerator``, and outputs changes as they occur:
    The following example opens a change stream on the ``restaurants`` collection
    and outputs changes as they occur:

    @norareidy norareidy merged commit 6885e67 into mongodb:standardization Jan 17, 2025
    5 checks passed
    @norareidy norareidy deleted the DOCSP-45200-change-streams branch January 17, 2025 18:46
    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