-
Notifications
You must be signed in to change notification settings - Fork 21
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
DOCSP-43911 - Implicit Client-Side Projection #242
Conversation
✅ Deploy Preview for mongodb-docs-csharp ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
source/whats-new.txt
Outdated
|
||
API reference page on MSDN. | ||
|
||
- Adds support for implicit client-side projection when using the ``Find()`` and |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
source/whats-new.txt
Outdated
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 |
There was a problem hiding this comment.
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).
source/whats-new.txt
Outdated
|
||
var find = collection | ||
.Find(doc => doc.Id == 1) | ||
.ToEnumerable() |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
source/whats-new.txt
Outdated
|
||
var enumerable = collection.AsQueryable() | ||
.Where(doc => doc.Id == 1) | ||
.AsEnumerable() |
There was a problem hiding this comment.
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.
source/whats-new.txt
Outdated
.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: |
There was a problem hiding this comment.
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.
source/whats-new.txt
Outdated
}; | ||
|
||
var aggregate = collection | ||
.Aggregate(pipeline, aggregateOptions) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I confused it with Aggregate<TResult>
: https://mongodb.github.io/mongo-csharp-driver/2.29.0/api/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.Aggregate.html
: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>`. |
There was a problem hiding this comment.
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.
source/whats-new.txt
Outdated
}; | ||
|
||
var aggregate = collection | ||
.Aggregate(pipeline, aggregateOptions) |
There was a problem hiding this comment.
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)
source/whats-new.txt
Outdated
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. |
There was a problem hiding this comment.
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
andSelect
- 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.
There was a problem hiding this comment.
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?
source/whats-new.txt
Outdated
.. code-block:: csharp | ||
|
||
// Enable client-side projection | ||
var findOptions = new FindOptions; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
source/whats-new.txt
Outdated
}; | ||
|
||
var queryable = collection | ||
.AsQueryable(translationOptions) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
source/whats-new.txt
Outdated
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-43911
Staging Links
Self-Review Checklist