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-43911 - Implicit Client-Side Projection #242

Merged
merged 8 commits into from
Oct 3, 2024

Conversation

mongoKart
Copy link
Collaborator

@mongoKart mongoKart commented Sep 26, 2024

Pull Request Info

PR Reviewing Guidelines

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

Staging Links

  • whats-new
  • 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 Sep 26, 2024

    Deploy Preview for mongodb-docs-csharp ready!

    Name Link
    🔨 Latest commit 2b6bd0a
    🔍 Latest deploy log https://app.netlify.com/sites/mongodb-docs-csharp/deploys/66fee3f12b7556000832f03f
    😎 Deploy Preview https://deploy-preview-242--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.

    Copy link
    Collaborator

    @jordan-smith721 jordan-smith721 left a comment

    Choose a reason for hiding this comment

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

    LGTM


    API reference page on MSDN.

    - Adds support for implicit client-side projection when using the ``Find()`` and
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    It won't be implicit.

    Client-side projections are potentially undesirable and the current thinking is that they will have to "enable" client side projections in order to use them.

    The current PR is not merged to master yet, but the two places client-side projections can be enabled are in the MongoClientSettings or in the FindOptions or AggregateOptions for an individual query.

    Theoretically they could be implicit, but that's not the current thinking.

    Copy link
    Collaborator Author

    @mongoKart mongoKart Oct 2, 2024

    Choose a reason for hiding this comment

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

    Thanks for clarifying! I was trying to figure this out from the relevant ticket and PR but must have missed this aspect. I hope I got it right in these code samples, but please correct me if I'm wrong.

    API reference page on MSDN.

    - Adds support for implicit client-side projection when using the ``Find()`` and
    ``Select()`` methods. In previous versions of the driver, you could perform client-side
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Beside the Find and Select methods this will apply to the Project pipeline stage builder (which is analogous to the Select method).


    var find = collection
    .Find(doc => doc.Id == 1)
    .ToEnumerable()
    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 not driver supported client-side projections. This is the user doing an EXPLICIT client-side projection by splitting their query into server-side and client-side parts and separating them by ToEnumerable.

    Copy link
    Collaborator Author

    @mongoKart mongoKart Oct 2, 2024

    Choose a reason for hiding this comment

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

    My understanding was that this is currently the only way to do it, which is why I presented it as the "before" example. Is that wrong?

    Either way, I rearranged things to hopefully make it clearer.


    var enumerable = collection.AsQueryable()
    .Where(doc => doc.Id == 1)
    .AsEnumerable()
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Also EXPLICIT like the Find example above.

    .Select(doc => new { R = MyFunction(doc.Name) });

    In {+driver-short+} v3.0, you can perform client-side projection directly in the
    ``Find()`` and ``Select()`` methods, as shown in the following examples:
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    Yes but... they have to enable client-side projections to do this.

    };

    var aggregate = collection
    .Aggregate(pipeline, aggregateOptions)
    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    Some of your tests call Aggregate() with no arguments, but I couldn't find that method overload and wasn't sure whether it accepted an options argument--hence the pipeline argument.

    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    The correct syntax is:

    collection.Aggregate(aggregateOptions)

    There is no overload that takes a pipeline.

    Aggregate is an extension method:

    public static IAggregateFluent<TDocument> Aggregate<TDocument>(this IMongoCollection<TDocument> collection, AggregateOptions options = null)

    and the options argument is optional so:

    collection.Aggregate()

    is the same as:

    collection.Aggregate(options: null)

    Copy link
    Collaborator Author

    @mongoKart mongoKart Oct 3, 2024

    Choose a reason for hiding this comment

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

    :ref:`csharp-aggregation`.

    For more information about this release, see the :github:`v3.0 release notes
    </mongodb/mongo-csharp-driver/releases/tag/v3.0.0>`.
    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    Link will be broken until actual release.

    @mongoKart mongoKart requested a review from rstam October 2, 2024 21:12
    };

    var aggregate = collection
    .Aggregate(pipeline, aggregateOptions)
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    The correct syntax is:

    collection.Aggregate(aggregateOptions)

    There is no overload that takes a pipeline.

    Aggregate is an extension method:

    public static IAggregateFluent<TDocument> Aggregate<TDocument>(this IMongoCollection<TDocument> collection, AggregateOptions options = null)

    and the options argument is optional so:

    collection.Aggregate()

    is the same as:

    collection.Aggregate(options: null)

    the ``Select()`` method, or the ``Project()`` aggregation stage.
    In previous versions of the driver, you could perform client-side
    projection only after calling the ``ToEnumerable()`` or ``AsEnumerable()`` method, and
    only within the ``Select()`` method.
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    In previous versions of the driver behavior depended on which LINQ provider you were using:

    • LINQ2: implicit client-side projections in Find, Project and Select
    • LINQ3: explicit client-side projections only

    In the 3.0 version of the driver implicit client-side projections are supported but only if EnableClientSideProjections == true

    By "explicit client-side projections" I mean calling ToEnumerable() or AsEnumerable() to specify where the client-side part of the query starts.

    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    Thanks. I reworded this section. Is it accurate to say that v3.0 supports implicit client-side projection when using the LINQ3 provider, so long as that setting is true?

    .. code-block:: csharp

    // Enable client-side projection
    var findOptions = new FindOptions;
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    var findOptions = new FindOptions();
    

    missing parenthesis

    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'm looking forward to IT renewing my Rider license so I can write these samples in an IDE...

    };

    var queryable = collection
    .AsQueryable(translationOptions)
    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 subtle but the actual argument to AsQueryable is an AggregateOptions value, not an ExpressionTranslationOptions value.

    We might want to be explicit about that.

    AsQueryable(translationOptions) does work but only because there is an implicit conversion from ExpressionTranslationOptions to AggregateOptions, and I'm not sure we're going to keep that implicit conversion.

    @mongoKart mongoKart requested a review from rstam October 3, 2024 16:39
    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.

    Sorry one small question I should have asked in a previous review.

    the ``Select()`` method, or the ``Project()`` aggregation stage with the LINQ3 provider.
    In previous versions of the driver, you could perform client-side
    projection with the LINQ3 provider only after calling the ``ToEnumerable()`` or
    ``AsEnumerable()`` method, and only within the ``Select()`` method.
    Copy link
    Collaborator

    Choose a reason for hiding this comment

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

    and only within the Select() method

    Why would this be the case? Once you're client-side you can do anything.

    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 suspect I inferred this from something in the Jira ticket.

    @mongoKart mongoKart requested a review from rstam October 3, 2024 18:35
    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

    @mongoKart mongoKart merged commit 45a6d4a into mongodb:v3.0 Oct 3, 2024
    6 checks passed
    @mongoKart mongoKart deleted the docsp-43911-client-projection branch October 3, 2024 21:45
    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