Skip to content

DOCSP-49786 - Projection methods #644

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 12 commits into
base: docsp-45382-comp-cvg
Choose a base branch
from

Conversation

mongoKart
Copy link
Collaborator

@mongoKart mongoKart commented Jun 4, 2025

A lot of this will be incorporated into the Server/Atlas docs eventually, but that's out of scope for this ticket

Pull Request Info

PR Reviewing Guidelines

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

Staging Links

  • aggregation
  • aggregation/linq
  • aggregation/stages
  • atlas-search
  • atlas-vector-search
  • crud/query/project
  • reference/quick-reference
  • serialization
  • serialization/poco
  • 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?

    Copy link

    netlify bot commented Jun 4, 2025

    Deploy Preview for docs-csharp ready!

    Name Link
    🔨 Latest commit 9cb1311
    🔍 Latest deploy log https://app.netlify.com/projects/docs-csharp/deploys/68430f32d6c7d4000851ae2f
    😎 Deploy Preview https://deploy-preview-644--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 project configuration.

    @mongoKart mongoKart marked this pull request as ready for review June 5, 2025 02:04
    Copy link
    Collaborator Author

    @mongoKart mongoKart Jun 5, 2025

    Choose a reason for hiding this comment

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

    I checked this file out from upstream/master. It doesn't need to be reviewed.

    @mongoKart mongoKart changed the title first draft DOCSP-49786 - Projection methods Jun 5, 2025
    Copy link
    Collaborator

    @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.

    There are a bunch of white space changes included in this PR, which is fine, but I wanted to call it out in case they're not intended.

    A few things to look at:

    Comment on lines 88 to 97
    { "_id" : { "$oid" : "573a13a0f29313caabd04a4f" }, "plot" : "A reporter, learning of time travelers visiting 20th century disasters, tries to change the history they know by averting upcoming disasters.", "title" : "Thrill Seekers", "score" : 0.926971435546875 }
    { "_id" : { "$oid" : "573a13d8f29313caabda6557" }, "plot" : "At the age of 21, Tim discovers he can travel in time and change what happens and has happened in his own life. His decision to make his world a better place by getting a girlfriend turns out not to be as easy as you might think.", "title" : "About Time", "score" : 0. 9267120361328125 }
    { "_id" : { "$oid" : "573a1399f29313caabceec0e" }, "plot" : "An officer for a security agency that regulates time travel, must fend for his life against a shady politician who has a tie to his past.", "title" : "Timecop", "score" : 0.9235687255859375 }
    { "_id" : { "$oid" : "573a13a5f29313caabd13b4b" }, "plot" : "Hoping to alter the events of the past, a 19th century inventor instead travels 800,000 years into the future, where he finds humankind divided into two warring races.", "title" : "The Time Machine", "score" : 0.9228668212890625 }
    { "_id" : { "$oid" : "573a13aef29313caabd2e2d7" }, "plot" : "After using his mother's newly built time machine, Dolf gets stuck involuntary in the year 1212. He ends up in a children's crusade where he confronts his new friends with modern techniques...", "title" : "Crusade in Jeans", "score" : 0.9228515625 }
    { "_id" : { "$oid" : "573a1399f29313caabcee36f" }, "plot" : "A time-travel experiment in which a robot probe is sent from the year 2073 to the year 1973 goes terribly wrong thrusting one of the project scientists, a man named Nicholas Sinclair into a...", "title" : "A.P.E.X.", "score" : 0.9199066162109375 }
    { "_id" : { "$oid" : "573a13c6f29313caabd715d3" }, "plot" : "Agent J travels in time to M.I.B.'s early days in 1969 to stop an alien from assassinating his friend Agent K and changing history.", "title" : "Men in Black 3", "score" : 0.919403076171875 }
    { "_id" : { "$oid" : "573a13d4f29313caabd98c13" }, "plot" : "Bound by a shared destiny, a teen bursting with scientific curiosity and a former boy-genius inventor embark on a mission to unearth the secrets of a place somewhere in time and space that exists in their collective memory.", "title" : "Tomorrowland", "score" : 0. 9191131591796875 }
    { "_id" : { "$oid" : "573a13b6f29313caabd477fa" }, "plot" : "With the help of his uncle, a man travels to the future to try and bring his girlfriend back to life.", "title" : "Love Story 2050", "score" : 0. 917755126953125 }
    { "_id" : { "$oid" : "573a13b3f29313caabd3ebd4" }, "plot" : "A romantic drama about a Chicago librarian with a gene that causes him to involuntarily time travel, and the complications it creates for his marriage.", "title" : "The Time Traveler's Wife", "score" : 0.9172210693359375 }
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    There's some extra spacing in the plot and title strings that I don't think is intentional.

    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    no, that's just how it pasted in from Rider. removed

    Comment on lines 46 to 49
    1. Use the ``Builders<TDocument>.Projection`` static property to create a
    ``ProjectionDefinitionBuilder<TDocument>`` object. The ``ProjectionDefinitionBuilder`` class
    provides a type-safe interface for defining a projection. ``TDocument`` represents the
    C# class that the collection's documents map to.
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Not strictly necessary, but I think this reads better:

    Suggested change
    1. Use the ``Builders<TDocument>.Projection`` static property to create a
    ``ProjectionDefinitionBuilder<TDocument>`` object. The ``ProjectionDefinitionBuilder`` class
    provides a type-safe interface for defining a projection. ``TDocument`` represents the
    C# class that the collection's documents map to.
    1. Use the ``Builders<TDocument>.Projection`` static property to create a
    ``ProjectionDefinitionBuilder<TDocument>`` object, where ``TDocument`` represents the
    C# class that the collection's documents map to. The ``ProjectionDefinitionBuilder`` class
    provides a type-safe interface for defining a projection.

    Comment on lines 125 to 129
    The ``Slice()`` method specifies the number of elements in an array to return in the query
    result. This is equivalent to using the ``$slice`` operator in the {+query-api+}.

    The following code example uses the ``Slice()`` method to return the first three elements
    of the ``cast`` array in the returned document:
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    This needs a tech review, but I think it's worth nit picking lists vs arrays in this case:

    Suggested change
    The ``Slice()`` method specifies the number of elements in an array to return in the query
    result. This is equivalent to using the ``$slice`` operator in the {+query-api+}.
    The following code example uses the ``Slice()`` method to return the first three elements
    of the ``cast`` array in the returned document:
    The ``Slice()`` method specifies the number of elements of a list or array to return in the query
    result field. This is equivalent to using the ``$slice`` operator in the {+query-api+}.
    The following code example uses the ``Slice()`` method to return the first three elements
    of the ``Cast`` list in the returned document's ``cast`` array:

    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    that's fair. Server only works with arrays and that's where I copied the text from

    Comment on lines 155 to 158
    To return elements from the end of an array, pass a negative integer to the ``Slice()``
    method. The method returns the specified number of elements from the end of the array.
    The following code example returns the last three elements of the ``cast`` array in the
    returned document:
    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
    To return elements from the end of an array, pass a negative integer to the ``Slice()``
    method. The method returns the specified number of elements from the end of the array.
    The following code example returns the last three elements of the ``cast`` array in the
    returned document:
    To return elements from the end of a collection, pass a negative integer to the ``Slice()``
    method.
    The following code example returns the last three elements of the ``Cast`` list in the
    returned document's ``cast`` array:

    Comment on lines 183 to 186
    To skip a specified number of elements in the array, pass the number of elements to skip
    as the first parameter and the number of elements to return as the second
    parameter. The following code example skips the first element in the
    ``cast`` array and returns the next three elements:
    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
    To skip a specified number of elements in the array, pass the number of elements to skip
    as the first parameter and the number of elements to return as the second
    parameter. The following code example skips the first element in the
    ``cast`` array and returns the next three elements:
    To skip a specified number of elements in a collection, pass the number of elements to skip
    as the first parameter and the number of elements to return as the second
    parameter. The following code example skips the first element in the
    ``Cast`` list and returns the next three elements in the ``cast`` array:

    Comment on lines 319 to 320
    The following code example projects each document's search score in a property named
    ``Score``:
    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
    The following code example projects each document's search score in a property named
    ``Score``:
    The following code example projects each document's search score in a property named
    ``score``:

    Comment on lines +430 to +431
    MetaTextScore
    ~~~~~~~~~~~~~
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    This is the only meta method with the Atlas only admonition - not sure if it's missing or if this can be applied to all searches?

    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    my understanding--and this might change during tech review--is that textScore is the only metadata field that you can retrieve from a search on a local deployment. But i think you can also use it in Atlas Search

    Comment on lines 355 to 358
    To retrieve score details, you must create a ``SearchOptions`` object that, set its
    ``ScoreDetails`` property to ``true``, and then pass this object to the ``Search()`` method.
    The following code example shows this process by projecting each document's search score
    details in a property named ``ScoreDetails``:
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    I found this a bit confusing because the property name and projection name were the same. Maybe change the projection name so it's clear they're distinct?

    Suggested change
    To retrieve score details, you must create a ``SearchOptions`` object that, set its
    ``ScoreDetails`` property to ``true``, and then pass this object to the ``Search()`` method.
    The following code example shows this process by projecting each document's search score
    details in a property named ``ScoreDetails``:
    To retrieve score details, create a ``SearchOptions`` object with its
    ``ScoreDetails`` property set to ``true``, and then pass this object to the ``Search()`` method.
    The following code example shows this process by projecting each document's search score
    details in a property named ``SearchScoreDetails``:

    Comment on lines +82 to +84
    The ``Expression()`` method lets you specify the structure of the returned documents
    by using a lambda expression. This is equivalent to specifying the structure of the
    returned documents in the ``$project`` aggregation stage in the {+query-api+}.
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    I couldn't find the Expression(), Include(), or Exclude() examples on this page - are they maybe not merged yet?

    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    yep, those examples will be missing until https://github.com/10gen/docs-mongodb-internal/pull/11902 is through external review

    @mongoKart mongoKart requested a review from rachel-mack June 6, 2025 15:58
    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.

    2 participants