Skip to content

DOCSP-47059: Work with BSON #263

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

Merged
merged 5 commits into from
Jun 6, 2025
Merged

Conversation

norareidy
Copy link
Collaborator

@norareidy norareidy commented Jun 3, 2025

Pull Request Info

PR Reviewing Guidelines

Edits the existing BSON page for style guide alignment and adds some content.

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

Staging Links

  • data-formats/modeling-bson-data
  • 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?
    • Are the page titles greater than 20 characters long and SEO relevant?
    • Did you add redirects?

    Copy link

    netlify bot commented Jun 3, 2025

    Deploy Preview for docs-php-library ready!

    Name Link
    🔨 Latest commit 36ac8c3
    🔍 Latest deploy log https://app.netlify.com/projects/docs-php-library/deploys/6841d8c38f389f0008bd6c60
    😎 Deploy Preview https://deploy-preview-263--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.

    @rustagir rustagir self-requested a review June 3, 2025 18:52
    selected classes (e.g. :phpmethod:`MongoDB\Client::getDatabase()`).
    **BSON**, or Binary JSON, is the data format that MongoDB uses to organize
    and store data. This data format includes all JSON data structure types and
    supports additional types, including dates, different-sized integers, ``ObjectId``
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    S: to resolve vale error

    Suggested change
    supports additional types, including dates, different-sized integers, ``ObjectId``
    also supports other types, such as dates, different-sized integers, ``ObjectId``

    Copy link
    Collaborator

    @rustagir rustagir left a comment

    Choose a reason for hiding this comment

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

    Good work, There are a few areas that I wanted to see some more context + some style guide fixes

    Comment on lines 23 to 24
    values, and binary data. The {+library-short+} provides the ``MongoDB\Model\BSONArray``
    and ``MongoDB\Model\BSONDocument`` types to store BSON data.
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    S: Use API links

    Comment on lines 28 to 29
    For a complete list of supported BSON types, see :manual:`BSON Types
    </reference/bson-types>` in the {+mdb-server+} manual.
    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
    For a complete list of supported BSON types, see :manual:`BSON Types
    </reference/bson-types>` in the {+mdb-server+} manual.
    To view a complete list of supported BSON types, see :manual:`BSON Types
    </reference/bson-types>` in the {+mdb-server+} manual.


    Persistable Classes
    -------------------
    You can create a BSON document by using the same notation you use to create an
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    S: style guide

    Suggested change
    You can create a BSON document by using the same notation you use to create an
    You can create a BSON document by using the same notation that you use to create an

    Comment on lines 69 to 71
    You can modify the contents of a BSON document by using the same notation you use to
    modify an associative array in {+language+}. This example makes the following changes
    to the :ref:`sample BSON document <php-bson-sample>`:
    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
    You can modify the contents of a BSON document by using the same notation you use to
    modify an associative array in {+language+}. This example makes the following changes
    to the :ref:`sample BSON document <php-bson-sample>`:
    You can modify the contents of a BSON document by using the same notation that you use to
    modify an associative array in {+language+}. This example makes the following changes
    to the :ref:`sample BSON document <php-bson-sample>`:

    },
    "coord" : [-73.982419, 41.579505]
    "cuisine" : "Pizza",
    "name" : "Mongo's Pizza"
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    S: consider using a name that doesn't include a char that needs escaping, unless you specifically want to demonstrate this (which is good too!)

    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    Updated, I don't think it's necessary to demonstrate

    Example
    ```````

    Consider the following ``Person`` class definition:
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    S: explain what is special/expected by defining the class this way

    Comment on lines 229 to 230
    you must specify serialization logic by defining the ``bsonSerialize()``
    and ``bsonUnserialize()`` methods.
    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
    you must specify serialization logic by defining the ``bsonSerialize()``
    and ``bsonUnserialize()`` methods.
    you must specify serialization logic by defining the ``bsonSerialize()``
    and ``bsonUnserialize()`` methods in your class definition.

    Comment on lines 244 to 248
    .. literalinclude:: /includes/bson.php
    :language: php
    :dedent:
    :start-after: start-backed-enum
    :end-before: end-backed-enum
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    S: consider adding highlighting for the methods of interest

    Comment on lines 252 to 256
    Enums cannot implement the ``MongoDB\BSON\Unserializable`` and
    ``MongoDB\BSON\Persistable`` interfaces, since enum cases have no
    state and cannot be instantiated like class objects. However, pure and backed
    enums can implement ``MongoDB\BSON\Serializable``, which you can use to
    override the default enum serialization behavior.
    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
    Enums cannot implement the ``MongoDB\BSON\Unserializable`` and
    ``MongoDB\BSON\Persistable`` interfaces, since enum cases have no
    state and cannot be instantiated like class objects. However, pure and backed
    enums can implement ``MongoDB\BSON\Serializable``, which you can use to
    override the default enum serialization behavior.
    Enums cannot implement the ``MongoDB\BSON\Unserializable`` and
    ``MongoDB\BSON\Persistable`` interfaces because enum cases have no
    state and cannot be instantiated like class objects. However, pure and backed
    enums can implement ``MongoDB\BSON\Serializable``, which you can use to
    override the default enum serialization behavior.

    :dedent:
    :start-after: start-backed-enum
    :end-before: end-backed-enum

    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    S: consider demonstrating an example as you did in the previous section of the serialization roundtrip

    @norareidy norareidy requested a review from rustagir June 5, 2025 15:09
    Comment on lines +82 to +87
    .. note::

    The preceding code changes only the in-memory values of the sample BSON
    document. It does not run any database operations that change values stored
    in MongoDB. To learn how to modify documents stored in MongoDB, see the
    :ref:`php-write-update` guide.
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    This looks good and addresses my concern!

    Copy link
    Collaborator

    @rustagir rustagir left a comment

    Choose a reason for hiding this comment

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

    looks great! thanks for implementing all the feedback

    Comment on lines 92 to 93
    The following sections describe how to configure your application's
    serialization of BSON data:
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    S: simplify

    Suggested change
    The following sections describe how to configure your application's
    serialization of BSON data:
    The following sections describe how to configure the way your application
    serializes BSON data:

    :start-after: start-enum-serialize
    :end-before: end-enum-serialize
    :language: php
    :dedent:
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    S: maybe its worth adding a sentence below here that says that the USER enum value was stored as a 1 in MongoDB, but deserialized correctly into the enum value. But can also leave out if its obvious/redundant.

    @norareidy norareidy requested review from a team and paulinevos and removed request for a team June 5, 2025 17:57
    @norareidy norareidy merged commit 90a66cc into mongodb:comp-cov Jun 6, 2025
    7 of 9 checks passed
    @norareidy norareidy deleted the DOCSP-47059-bson branch June 6, 2025 15:04
    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