Skip to content

DOCSP-45003: Specify Fields to Include #291

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 7 commits into from
Nov 19, 2024

Conversation

mcmorisi
Copy link
Collaborator

@mcmorisi mcmorisi commented Nov 13, 2024

Pull Request Info

PR Reviewing Guidelines

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

Staging Links

  • fundamentals/crud/read-operations/project
  • fundamentals/crud/read-operations
  • 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 Nov 13, 2024

    Deploy Preview for mongodb-docs-csharp ready!

    Name Link
    🔨 Latest commit 04dcc4e
    🔍 Latest deploy log https://app.netlify.com/sites/mongodb-docs-csharp/deploys/6737aa575bf1c100081780d8
    😎 Deploy Preview https://deploy-preview-291--mongodb-docs-csharp.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.

    @mcmorisi mcmorisi marked this pull request as ready for review November 13, 2024 19:56
    @stephmarie17 stephmarie17 self-requested a review November 13, 2024 22:25
    Copy link
    Collaborator

    @stephmarie17 stephmarie17 left a comment

    Choose a reason for hiding this comment

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

    LGTM with a few small comments!


    The following example uses the ``Find()`` method to find all restaurants in which the ``name``
    field value is ``"Emerald Pub"``. Then, the code calls the ``Project()``
    method to instruct the find operation to include the ``name`` and ``address`` fields
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    [q] Should this be updated to match the code snippet?

    Suggested change
    method to instruct the find operation to include the ``name`` and ``address`` fields
    method to instruct the find operation to include the ``name`` and ``cuisine`` fields

    Specify Fields to Exclude
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    To specify the fields to include from the result, chain the ``Project()`` method
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Typo:

    Suggested change
    To specify the fields to include from the result, chain the ``Project()`` method
    To specify the fields to exclude from the result, chain the ``Project()`` method

    @mcmorisi mcmorisi requested review from a team and rstam and removed request for a team November 14, 2024 14:15
    [BsonElement("coord")]
    public double[] Coordinates { get; set; }

    public string Street { get; set; }
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Did you mean to omit [BsonElement] here?


    public class Address
    {
    public string Building { get; set; }
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Did you mean to omit [BsonElement] here?


    In this guide, you can learn how to specify which fields to return from a read
    operation by using a **projection**. A projection is a document that specifies
    which fields MongoDB returns from a query.
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Something to consider is that projections don't play nicely with POCOs.

    When you only return some of the fields from the server your POCO is incomplete. Depending on how the serialization is done either the missing fields will be null (or other suitable default value) in your POCO result or perhaps even an exception might be thrown for missing fields.

    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'll update this page to avoid using POCOs

    @mcmorisi mcmorisi requested a review from rstam November 15, 2024 20:08
    Copy link
    Collaborator

    @rstam rstam left a comment

    Choose a reason for hiding this comment

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

    LGTM

    @mcmorisi mcmorisi merged commit 79d61d8 into mongodb:master Nov 19, 2024
    6 checks passed
    @mcmorisi mcmorisi deleted the DOCSP-45003-project branch November 19, 2024 13:56
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mcmorisi added a commit that referenced this pull request Nov 19, 2024
    mongoKart pushed a commit to mongoKart/docs-csharp that referenced this pull request May 16, 2025
    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