Skip to content

DOCSP-43911 - Implicit Client-Side Projection #242

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 8 commits into from
Oct 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,38 @@ The 3.0 driver release includes the following new features:
This type is available in .NET 5 and later.
To learn more about the ``Half`` type, see the
`Half Struct <https://learn.microsoft.com/en-us/dotnet/api/system.half?view=net-8.0>`__
API reference page on MSDN.

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.

``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).

projection only after calling the ``ToEnumerable()`` or ``AsEnumerable()`` method, and
only by using the ``Select()`` method, similar to the following examples:

.. code-block:: csharp

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.

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

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.


.. code-block:: csharp

var find = collection
.Find(doc => doc.Id == 1)
.Project(doc => new { R = MyFunction(doc.Name) });

var queryable = collection.AsQueryable()
.Where(doc => doc.Id == 1)
.Select(doc => new { R = MyFunction(doc.Name) });

.. _csharp-version-2.28:

What's New in 2.28
Expand Down
Loading