<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:53 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-456] Support linq projections to only pull back referenced fields.</title>
                <link>https://jira.mongodb.org/browse/CSHARP-456</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;It should only pull back fields required for projection.  In addition, it should support these forms&lt;br/&gt;
1) simple projections: x.FirstName&lt;br/&gt;
2) complex projections: x.FirstName + &quot; &quot; + x.LastName&lt;br/&gt;
3) anonymous projections: new { Name = x.FirstName + &quot; &quot; + x.LastName&lt;br/&gt;
4) class Projections: new PersonName(x.FirstName, x.LastName) &lt;/p&gt;
{ Age = x.BirthDate.ToAge() }
&lt;p&gt;);&lt;/p&gt;</description>
                <environment></environment>
        <key id="37308">CSHARP-456</key>
            <summary>Support linq projections to only pull back referenced fields.</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="craig.wilson@mongodb.com">Craig Wilson</assignee>
                                    <reporter username="craig.wilson@mongodb.com">Craig Wilson</reporter>
                        <labels>
                            <label>C#</label>
                            <label>linq</label>
                    </labels>
                <created>Fri, 27 Apr 2012 13:14:09 +0000</created>
                <updated>Sat, 4 Apr 2015 22:55:41 +0000</updated>
                            <resolved>Sat, 4 Apr 2015 22:55:41 +0000</resolved>
                                    <version>1.4.2</version>
                                                                        <votes>53</votes>
                                    <watches>40</watches>
                                                                                                                <comments>
                            <comment id="872965" author="craiggwilson" created="Sat, 4 Apr 2015 22:55:41 +0000"  >&lt;p&gt;This has been implemented in the 2.0 driver and, when LINQ is rewritten, &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-601&quot; title=&quot;Linq to Aggregation Framework&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-601&quot;&gt;&lt;del&gt;CSHARP-601&lt;/del&gt;&lt;/a&gt;, it will be fully realized.&lt;/p&gt;</comment>
                            <comment id="465376" author="persi" created="Wed, 4 Dec 2013 13:02:27 +0000"  >&lt;p&gt;Same problem here, should not be a minor bug, the problem is hidden and unexpected.&lt;/p&gt;</comment>
                            <comment id="437698" author="adro75" created="Tue, 8 Oct 2013 21:34:11 +0000"  >&lt;p&gt;Same here, this is killing our ability to use linq queries on large documents &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/sad.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                            <comment id="430374" author="roysvork" created="Tue, 24 Sep 2013 14:55:23 +0000"  >&lt;p&gt;Will do... let me know if there&apos;s anything I might be able to assist with.&lt;/p&gt;</comment>
                            <comment id="430372" author="craiggwilson" created="Tue, 24 Sep 2013 14:50:55 +0000"  >&lt;p&gt;You&apos;ll want to track &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-601&quot; title=&quot;Linq to Aggregation Framework&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-601&quot;&gt;&lt;del&gt;CSHARP-601&lt;/del&gt;&lt;/a&gt;.  &lt;/p&gt;</comment>
                            <comment id="430335" author="roysvork" created="Tue, 24 Sep 2013 13:47:59 +0000"  >&lt;p&gt;Any updates on this one? Would be really useful for us!&lt;/p&gt;</comment>
                            <comment id="382213" author="mkennedy66996693" created="Tue, 16 Jul 2013 15:46:38 +0000"  >&lt;p&gt;Hi Daniel and Craig,&lt;/p&gt;

&lt;p&gt;Thanks for the update Craig. Sounds like it&apos;s on the right track!&lt;/p&gt;</comment>
                            <comment id="382163" author="craiggwilson" created="Tue, 16 Jul 2013 14:50:48 +0000"  >&lt;p&gt;Mike and Daniel,&lt;br/&gt;
  This is exactly what the rewrite does.  You can see the current work here: &lt;a href=&quot;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp601&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp601&lt;/a&gt;.  It is about 90% done.  There are a couple things to know about it.  It supports Aggregation Framework natively, although that has to be optet-in.  In every linq query, both query based and Aggregation Framework based, the final projection will always be applied client-side.  However, we inspect that expression and only pull back the fields that are necessary to do the client-side projection.  You&apos;ll see we can do some extremely complex projections client-side as long as we provide a way to drop in just the necessary fields (&lt;a href=&quot;https://github.com/craiggwilson/mongo-csharp-driver/blob/csharp601/MongoDB.DriverUnitTests/Linq/Translators/Methods/SelectTests_Query.cs#L271&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/craiggwilson/mongo-csharp-driver/blob/csharp601/MongoDB.DriverUnitTests/Linq/Translators/Methods/SelectTests_Query.cs#L271&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;  As far as partially populated entities, that will likely not ever happen.  The only way it would get included is if we supported proxy types to lazy-load the remaining fields.  That is a wholely different discussion.  So, the solution is for the user to create &quot;Summary&quot; objects that contain exactly what they need and project into them.&lt;/p&gt;</comment>
                            <comment id="382156" author="daniel.sinclair@nupe.com" created="Tue, 16 Jul 2013 14:42:18 +0000"  >&lt;p&gt;Hey Mike, yep. This is where I am too. Come to think of it, I wonder what&apos;s in store for the Linq/Aggregation support Craig? Presumably that will also require dynamic entities or suffer partially populate POCOS. I ran into this last year and ended up returning the aggregated queries as JSON rather than serializing through POCO but it wasn&apos;t pretty because that meant no language support for the queries (which also had to be converted into JSON).&lt;/p&gt;

&lt;p&gt;Overall, I think partially populated POCOs are a neat solution for the web, and I don&apos;t see a problem with the driver returning partial entities as long as ALL those fields are nullable. That&apos;s something that could be easily verified during the projection, right?&lt;/p&gt;</comment>
                            <comment id="382139" author="mkennedy66996693" created="Tue, 16 Jul 2013 14:28:48 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;Glad to see this is being addressed. &lt;/p&gt;

&lt;p&gt;Given the complexity of supporting any projection whatsoever, could you start by doing this.&lt;/p&gt;

&lt;p&gt;1. For SIMPLE projections, do the projection in mongo&lt;br/&gt;
2. For more complex ones, fall back to what you&apos;re doing now (projections on the client).&lt;/p&gt;

&lt;p&gt;So for example, it seems odd that this would return the full document and then pull out the one field:&lt;/p&gt;

&lt;p&gt;var activeUserNames = ctx.Users.Where(u =&amp;gt; u.IsActive).Select(u =&amp;gt; u.Name).ToArray();&lt;/p&gt;

&lt;p&gt;Surely these types of queries are very common and perf would go up if you supported them.&lt;/p&gt;

&lt;p&gt;As an example, I have a bunch of docs each around 10K. I just wanted a list of IDs kind of like above. Apparently we are pulling back tons of data just to get a list of integers.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Michael&lt;/p&gt;</comment>
                            <comment id="379665" author="daniel.sinclair@nupe.com" created="Fri, 12 Jul 2013 10:02:36 +0000"  >&lt;p&gt;Thanks Craig. Comments noted. I&apos;ve only compiled the code above with&lt;br/&gt;
notepad.exe so far, but the IQueryable&amp;lt;T&amp;gt; consumer is a web client as I&apos;m&lt;br/&gt;
handing it out directly through ASP.Net Web API, which means Json.Net&lt;br/&gt;
serialization. I&apos;m expecting that to work as expected, but I take your&lt;br/&gt;
point about not being able to &quot;do any further filtering on iq&quot;. If that&apos;s a&lt;br/&gt;
problem, I guess I&apos;ll find out pretty quickly as soon as something that&lt;br/&gt;
consumes my All() function tries to do that. Off the top of my head, I&apos;m&lt;br/&gt;
pretty sure I DON&apos;T do that yet and all the Where() clauses are bundled&lt;br/&gt;
into the original query for passing through to the driver, hence the reason&lt;br/&gt;
for this. But I guess I&apos;ll find out soon enough if there&apos;s a&lt;br/&gt;
non-serialization consumer.&lt;/p&gt;


</comment>
                            <comment id="379032" author="craiggwilson" created="Thu, 11 Jul 2013 16:17:16 +0000"  >&lt;p&gt;It is still IQueryable&amp;lt;T&amp;gt;.  Otherwise, you wouldn&apos;t be able to assign it back the same iq variable.  However, this isn&apos;t going to go through the normal serialization machinery anymore and will return a T with just the Id field populated, and then we are in a similar boat as described above with semi-populated entities.  I can&apos;t stop you from doing this so you could probably figure out someway to work this in as an extension method that takes just field names and preserves the return type.&lt;/p&gt;

&lt;p&gt;Now, at this point in your query, you can&apos;t do any further filtering on iq though without this going into the Aggregation Framework.  There are circumstances when this would still be possible, but it would be extremely difficult to get right and lots of edge cases exist, so that won&apos;t be in the initial version of the new linq provider.&lt;/p&gt;</comment>
                            <comment id="378960" author="daniel.sinclair@nupe.com" created="Thu, 11 Jul 2013 15:26:34 +0000"  >&lt;p&gt;That&apos;s a very fair point about spliced Person types Craig. I can understand why you wouldn&apos;t want to do that. For me, I&apos;m basically working in Json at both ends and there&apos;s lots of assumed flexibility. Almost every field is nullable and hence stripped out on the wire anyway. In fact I wonder sometimes why I&apos;m (de)serializing into .Net at all. However, .net is a nice place to write some complex code and the strict type safety means getting rid of all magic strings. So Linq expressions are a perfect way not only for refactoring tool support but also for building a repository pattern with a common interface that would work on various DB providers, not least a unit test provider.&lt;/p&gt;

&lt;p&gt;We can already cope with partial updates, so a partial Person is turned into a pattern of $set type operations with the help of &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonIgnoreIfNull&amp;#93;&lt;/span&gt; and I can do similar things to clear fields with $unset.&lt;/p&gt;

&lt;p&gt;Interesting comment about there being no MongoCursor, but I guess I&apos;m going to need to construct a Where() clause somehow myself, but at least I can now do field restruction with that projection support you&apos;ve put into this build.&lt;/p&gt;

&lt;p&gt;Your code example has got me thinking again though. So in my previous stab;&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;IQueryable&amp;lt;T&amp;gt; iq = MongoDB.Driver.Linq.LinqExtensionMethods.AsQueryable(Collection);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;iq = iq.Where( .. some criteria ..);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// bring back Id field only&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;iq = iq.Select(e =&amp;gt; new T() { Id=e.Id } );&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;What type is iq returning in the above case? Is it still type compatible with IQueryable&amp;lt;T&amp;gt;? Or is that all down to serialization...in which case I&apos;m fine I guess as long as the fields I&apos;m skipping are nullable.&lt;/p&gt;</comment>
                            <comment id="378939" author="craiggwilson" created="Thu, 11 Jul 2013 15:09:54 +0000"  >&lt;p&gt;Yeah, but the problem with projections is that restricting fields also changes the type.  For instance, what does it mean to have a full Person entity with only the Id and Name field populated?  That could be very misleading to the consumers of your code, which of course is your problem and not really ours (except that we have now enabled that to happen and will subsequently get questions about). In other words, if I have an instance of a Person, do I have the full thing or just a projected version?   Regardless, the side-band kinda thing you are referring to would be some extension methods you&apos;d probably cook up yourself which would, underneath, build up a Tuple expression.  For instance:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;public virtual IQueryable&amp;lt;T&amp;gt; All(string[] fieldNames, params Expression&amp;lt;Func&amp;lt;T, bool&amp;gt;&amp;gt;[] rules)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    IQueryable&amp;lt;T&amp;gt; iq = MongoDB.Driver.Linq.LinqExtensionMethods.AsQueryable(Collection);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    // Add in security and criteria&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    iq = iq.Where(GetSecureReadExpression());&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    iq = iq.Where(ExpressionHelpers.CombinePredicateExpressions(rules));&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    // ONLY DREAMING!!&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    IQueryable&amp;lt;Tuple&amp;lt;ObjectId, string, int&amp;gt;&amp;gt; fieldRestrictedIQ = iq.Select&amp;lt;ObjectId, string, int&amp;gt;(&quot;Id&quot;, &quot;Name&quot;, &quot;Age&quot;);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    return iq;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;There would obviously need to be some type knowledge here which is what I was referring to above, but this is possible.  This particular extension method would build an expression tree.  You could have N number of these for the varying cardinality necessary.  You could also go without types and return a BsonDocument or Dictionary&amp;lt;string, object&amp;gt;, but then your application would have to figure out how to decipher what this means.&lt;/p&gt;

&lt;p&gt;Even worse for us is that if you pull back a partially reconstituted Person instance, then what happens when the user calls Save(person)?  It would overwrite all the data that wasn&apos;t pulled back with the default values in the entity.  This would be horrible.&lt;/p&gt;

&lt;p&gt;I guess in summary, we aren&apos;t going to put anything like this in the box and you&apos;re gonna have to write some code on your own to make this work like want.  The hook that is there for you to do this is that Select takes an Expression which you can construct yourself.  &lt;/p&gt;

&lt;p&gt;BTW: We can&apos;t provide access to the underlying MongoCursor because it doesn&apos;t exist.  Particularly because the next version of the Linq provider will also be support Aggregation Framework which doesn&apos;t use a cursor to begin with.&lt;/p&gt;</comment>
                            <comment id="378925" author="daniel.sinclair@nupe.com" created="Thu, 11 Jul 2013 14:52:57 +0000"  >&lt;p&gt;Actually, it&apos;s a little simpler than this. Everything I&apos;ve done so far above is a means to an end. I&apos;m perfectly happy with strongly typed linq queries. I don&apos;t need/want dynamic queries any other way. Far from it. It&apos;s just the field restriction that I need. I don&apos;t need &lt;b&gt;that&lt;/b&gt; part to be in Linq but as per the support mentioned in this ticket it would be the &lt;b&gt;only&lt;/b&gt; way to get the server to filter fields and return a streaming IQueryable.&lt;/p&gt;

&lt;p&gt;I think projection via Select() is the right thing to do for the Linq driver, but I&apos;d be perfectly happy with any other mechanism that allowed me to trim the resultset, however side-band it might be. For instance, if there was some other way to influence the underlying MongoCursor rather than construction an Expression just to feed into the Linq Select().&lt;/p&gt;

&lt;p&gt;This is probably where I&apos;d like to be;&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        public virtual IQueryable&amp;lt;T&amp;gt; All(string[] fieldNames, params Expression&amp;lt;Func&amp;lt;T, bool&amp;gt;&amp;gt;[] rules)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;            IQueryable&amp;lt;T&amp;gt; iq = MongoDB.Driver.Linq.LinqExtensionMethods.AsQueryable(Collection);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;            // Add in security and criteria&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;            iq = iq.Where(GetSecureReadExpression());&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;            iq = iq.Where(ExpressionHelpers.CombinePredicateExpressions(rules));&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;            // ONLY DREAMING!!&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;            iq.GetMongoCursor().SetFields(fieldNames);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;            return iq;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;I don&apos;t expect that Expression building stuff is going to work out well with types, but if I can limit the scope of fields that restriction can be used with (which I can), I could do this ugly mess;&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; fieldName &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; fieldNames)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; iq.Select(getFieldProjection(fieldName);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;where&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;Expression&amp;lt;Func&amp;lt;T, bool&amp;gt;&amp;gt; getFieldProjection(string fieldName)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; switch(fieldName)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;   case &quot;Id&quot;: return e =&amp;gt; new T() { Id=e.Id };&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;   case &quot;Name&quot; : return e =&amp;gt; new T() { Name=e.Name };&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;   default: throw ...&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Google hangout is good with me with this email account.&lt;/p&gt;</comment>
                            <comment id="378888" author="craiggwilson" created="Thu, 11 Jul 2013 14:21:08 +0000"  >&lt;p&gt;Gotcha.  Yeah, you are getting into territory explored by many who are attempting to use Linq.  Linq requires typing and therefore you are going to have to resort to either building up expressions manually (as you did above) or use something else that is Linq-ish.  For instance, Microsoft has a sample called Dynamic Linq (&lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx&lt;/a&gt;) that is more flexible but possibly does what you are looking for.  Is very possible to do something like this with a little effort building a parser:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var queryable = collection.AsQueryable().Where(&quot;Age &amp;gt; 23&quot;).Select(t =&amp;gt; new Tuple&amp;lt;ObjectId, string&amp;gt;(t.Id, t.Name));&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;I&apos;ve obviously put the Age into a string, which could arguable come from some user provided value.  That is relatively easy.  The difficult part is the projection piece.  Because you are wanting to use Linq, you need a strongly typed result and having the user provide arbitrary fields which could be of any type makes that an extremely difficult problem.  It feels like you need to be working with dynamic types and not Linq.  We will have support for dynamic types with version 2.0 of the driver.&lt;/p&gt;

&lt;p&gt;So even with the resolution of this ticket, you are going to need to do some pretty crazy stuff to get what you want as it is unlikely we&apos;ll be providing untyped Linq-ish behavior.&lt;/p&gt;

&lt;p&gt;BTW: I&apos;d also like to note that it is sometimes difficult to get performance out of MongoDB when you are allowing your users to provide arbitrary query expressions.  This is because you&apos;d need to know all the possible permutations of things the user would do and create an index for each of them.  This might be possible on small documents, but for large documents, things start to get hairy.&lt;/p&gt;

&lt;p&gt;If you&apos;d like, I&apos;m happy to jump on a google hangout and talk this out with you.&lt;/p&gt;</comment>
                            <comment id="378874" author="daniel.sinclair@nupe.com" created="Thu, 11 Jul 2013 14:05:22 +0000"  >&lt;p&gt;Thanks Craig&lt;br/&gt;
Yes, so I&apos;m mainly using Linq declaratively for expressions, but there are cases where I want to trim the resultset with a filter from an external source, which is a string field name. The Expression building stuff is just Linq true - I&apos;m just trying to work out how I can hook into your provider effectively.&lt;/p&gt;

&lt;p&gt;Your comment about not knowing the types is very troubling.&lt;/p&gt;

&lt;p&gt;The .Include trick is what I&apos;m doing/abandoned today, but unless I&apos;ve missed something (quite probably) doesn&apos;t that require a cursor? I still want to return IQueryable&amp;lt;&amp;gt;. The trouble is that AsQueryable&amp;lt;&amp;gt; on the cursor (as does your foreach I think) fetches all the data because it&apos;s the standard Linq one working over IEnumerable?, even though the .Include takes place on the server I believe.&lt;/p&gt;

&lt;p&gt;So what I&apos;m trying to do is this &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;use linq for query&lt;/li&gt;
	&lt;li&gt;pass the name of a string field for restriction/projection (without knowing types) that filters server-side&lt;/li&gt;
	&lt;li&gt;return MongoDB.Driver.Linq.LinqExtensionMethods.AsQueryable&lt;/li&gt;
&lt;/ul&gt;

</comment>
                            <comment id="378792" author="craiggwilson" created="Thu, 11 Jul 2013 12:32:05 +0000"  >&lt;p&gt;Hi Daniel,&lt;br/&gt;
  Linq is about typed lambda expressions getting turned into some underlying query.  What you are demonstrating above isn&apos;t really typed as you don&apos;t really know until runtime what you actually want to select out.  So yes, your solution above by building your own expression tree would be the way to do this.  This, BTW, is also how you&apos;d need to do this for any other linq provider as well.  One of the flaws with this approach is that you need to know the types of each of the field, and all you have is their field name.  This is going to make figuring out the return type (Tuple&amp;lt;&amp;gt;) very difficult.  If you can make assumptions (like all fields are of type string) as you did in your example, then that isn&apos;t much of a problem.&lt;/p&gt;

&lt;p&gt;  Just to point out, if you want to mix Linq for predicates and still use something like this, you can do something like this today.&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  var collection = db.GetCollection&amp;lt;BsonDocument&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  var fields = Fields.Include(&quot;_id&quot;).Include(&quot;Name&quot;);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  var query = Query.Where&amp;lt;T&amp;gt;(t =&amp;gt; t.Age &amp;gt; 23);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  foreach(BsonDocument doc in collection.Find(query).SetFields(fields))&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    // do something in here...&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;  }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</comment>
                            <comment id="378761" author="daniel.sinclair@nupe.com" created="Thu, 11 Jul 2013 10:54:14 +0000"  >&lt;p&gt;What&apos;s the optimal way hook into this if I have string field names as opposed to early bound? &lt;/p&gt;

&lt;p&gt;var fields[] = &lt;/p&gt;
{&quot;Id&quot;,&quot;Name&quot;}
&lt;p&gt;; &lt;/p&gt;

&lt;p&gt;Am I going to have to build up an Expression.Lambda to pass into Select() by hand? &lt;/p&gt;

&lt;p&gt;eg. something like this? &lt;/p&gt;

&lt;p&gt;var projection = Expression.Lambda&amp;lt;Func&amp;lt;T, Tuple&amp;lt;string, string&amp;gt;&amp;gt;&amp;gt;( &lt;br/&gt;
  Expression.Call(typeof(Tuple), &quot;Create&quot;, new[] &lt;/p&gt;
{typeof(string), typeof(string)}
&lt;p&gt;, &lt;br/&gt;
    Expression.PropertyOrField(param, &quot;Id&quot;), &lt;br/&gt;
    Expression.PropertyOrField(param, &quot;Name&quot;)), param); &lt;/p&gt;


&lt;p&gt;Ick.&lt;/p&gt;</comment>
                            <comment id="378087" author="craiggwilson" created="Wed, 10 Jul 2013 15:44:20 +0000"  >&lt;p&gt;Awesome, thanks so much.  Yes, that is it and, in this case, it should only bring back the Id field.  You shouldn&apos;t need to do anything special for that to happen automatically.&lt;/p&gt;</comment>
                            <comment id="378074" author="daniel.sinclair@nupe.com" created="Wed, 10 Jul 2013 15:29:34 +0000"  >&lt;p&gt;I&apos;d like to be putting this through it&apos;s paces, but I&apos;m missing the syntax. I want to use field restriction on the server with the linq syntax.&lt;/p&gt;

&lt;p&gt;Did I miss an example code snippit somewhere? I&apos;m guessing it will be something like this, but I want to make sure I have the right IQueryable and I&apos;m not accidentally doing it in memory (especially since the MongoDB log doesn&apos;t reflect field-restriction so it&apos;s not easy to tell);&lt;/p&gt;

&lt;p&gt;            IQueryable&amp;lt;T&amp;gt; iq = MongoDB.Driver.Linq.LinqExtensionMethods.AsQueryable(Collection);&lt;/p&gt;

&lt;p&gt;            iq = iq.Where( .. some criteria ..);&lt;/p&gt;

&lt;p&gt;            // bring back Id field only&lt;br/&gt;
            iq = iq.Select(e =&amp;gt; new T() &lt;/p&gt;
{ Id=e.Id }
&lt;p&gt; );&lt;/p&gt;</comment>
                            <comment id="341526" author="craiggwilson" created="Wed, 22 May 2013 13:45:32 +0000"  >&lt;p&gt;Ok guys... The branch I posted above (&lt;a href=&quot;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp601&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp601&lt;/a&gt;) has the current version of this completely on top of master; it is completely up-to-date.  I&apos;d consider this ~90% complete where there are some known things lacking (like $elemMatch in a projection) and there are probably some bugs.  However, all our current tests pass and all the existing linq expressions from the old library are still supported.  This should be a drop-in replacement for the old queries.&lt;/p&gt;

&lt;p&gt;That being said, this isn&apos;t released because I&apos;m quite sure there are a few bugs related to edge cases.  Since you all seem so eager, it&apos;d be a great help to put this through the ringer and let me know of things that should work that don&apos;t and things that shouldn&apos;t work that do (for instance, we send an query to the server it can&apos;t process, but no error comes back).  You can just pull this branch, build it, and use it instead of the official libraries.&lt;/p&gt;

&lt;p&gt;Hope that is enough for now... we are targeting this for the next major/minor version.  As in, if we release a 1.9, then this will be in it.  Otherwise, it will be in 2.0.  We are doing lots of other things right now in addition to this, so it is taking a bit longer than we wanted.&lt;/p&gt;
</comment>
                            <comment id="341410" author="daniel.sinclair@nupe.com" created="Wed, 22 May 2013 10:43:46 +0000"  >&lt;p&gt;+1&lt;/p&gt;</comment>
                            <comment id="341371" author="zaidmasud" created="Wed, 22 May 2013 08:54:38 +0000"  >&lt;p&gt;I agree with Avishay here. Since it&apos;s taking so long to get to the full solution, an interim FluentMongo-like solution, even supporting very basic projections, will be very valuable for driver users.&lt;/p&gt;</comment>
                            <comment id="341339" author="avish" created="Wed, 22 May 2013 07:32:17 +0000"  >&lt;p&gt;Since LINQ to AF seems like a pretty big effort, maybe there&apos;s value in providing partial support for simple projections, using the approach outlined above of instantiating the document class and only filling in the required properties/fields (a-la FluentMongo), and falling back to the current solution of client-side projection if the document class has a constructor map or ISupportInitialize or anything else that might get in the way. I think this should cover a lot of cases with relatively low cost. Any chance of that happening? If someone were to contribute a pull request that does this, would you pull it?&lt;/p&gt;

</comment>
                            <comment id="336286" author="daniel.sinclair@nupe.com" created="Wed, 15 May 2013 16:14:51 +0000"  >&lt;p&gt;Is there a relatively stable codebase for projection with IQueryable&amp;lt;&amp;gt; yet?&lt;/p&gt;</comment>
                            <comment id="281416" author="craiggwilson" created="Tue, 5 Mar 2013 01:17:18 +0000"  >&lt;p&gt;No, no production ready version with these changes.  This is still a ways off from being fully baked.&lt;/p&gt;</comment>
                            <comment id="281410" author="daniel.sinclair@nupe.com" created="Tue, 5 Mar 2013 01:05:05 +0000"  >&lt;p&gt;Oh - I thought this &lt;b&gt;was&lt;/b&gt; the master branch? Is there a production ready&lt;br/&gt;
version with these changes?&lt;/p&gt;</comment>
                            <comment id="281400" author="craiggwilson" created="Tue, 5 Mar 2013 00:50:21 +0000"  >&lt;p&gt;Be careful (and don&apos;t use in production).  This is unreviewed code that is far off master at this point.  It won&apos;t get pushed back into master for a little while.&lt;/p&gt;</comment>
                            <comment id="281348" author="daniel.sinclair@nupe.com" created="Mon, 4 Mar 2013 23:27:00 +0000"  >&lt;p&gt;pulled it - will do!&lt;/p&gt;</comment>
                            <comment id="281024" author="craiggwilson" created="Mon, 4 Mar 2013 17:50:49 +0000"  >&lt;p&gt;I will work for both normal queries and aggregation queries.&lt;/p&gt;</comment>
                            <comment id="277505" author="adro75" created="Wed, 27 Feb 2013 21:39:59 +0000"  >&lt;p&gt;So, will this feature work for normal queries too or just aggregated queries? I&apos;m facing the same situation where I have a massive subdocument property that I don&apos;t want to pull into memory (and it&apos;s not part of my mapped class). My linq statement can&apos;t, unfortunately just be injected into the MongoCollection because they have paging and sorting expressions as well.&lt;/p&gt;</comment>
                            <comment id="235652" author="craiggwilson" created="Thu, 10 Jan 2013 00:50:50 +0000"  >&lt;p&gt;I have this mostly working, but it is tied up in the work needed to support linq to Aggregation framework.  I&apos;m currently working on getting GroupBy&apos;s translated into the $group pipeline element.  You can see the current work here...  &lt;a href=&quot;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp601/MongoDB.Driver/Linq&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp601/MongoDB.Driver/Linq&lt;/a&gt;. It hasn&apos;t been cleaned up yet, so there is likely some cruft hanging around.  &lt;/p&gt;</comment>
                            <comment id="235648" author="chrisdrobison" created="Thu, 10 Jan 2013 00:42:45 +0000"  >&lt;p&gt;I&apos;m working on a project where documents might get big. I&apos;d like to contribute to this if I can. Is there any place I can help?&lt;/p&gt;</comment>
                            <comment id="211303" author="daniel.sinclair@nupe.com" created="Mon, 10 Dec 2012 18:50:02 +0000"  >&lt;p&gt;Actually, I wasn&apos;t reading it right. The query restriction doesn&apos;t show up in the log, but having looked directly in the buffer being sent/returned from Mongo (I couldn&apos;t use NetMon because I&apos;m on localhost) it appears to be doing the right thing.&lt;/p&gt;

&lt;p&gt;So for my case at least, this is a usable workaround. I appreciate this may not be the general case, but it seems to get me out of a pickle!&lt;/p&gt;</comment>
                            <comment id="211247" author="daniel.sinclair@nupe.com" created="Mon, 10 Dec 2012 18:07:58 +0000"  >&lt;p&gt;I&apos;m looking forward to the Aggregation integration, that will be&lt;br/&gt;
tremendously beneficial, and so of course you&apos;re right &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/sad.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt; I just tried&lt;br/&gt;
instead of this;&lt;/p&gt;

&lt;p&gt;return this.Collection.AsQueryable&amp;lt;T&amp;gt;()&lt;br/&gt;
                .Where(linqExpression);&lt;/p&gt;

&lt;p&gt;using this;&lt;/p&gt;

&lt;p&gt;            var mc = this.Collection.FindAs&amp;lt;T&amp;gt;(Query.Where(linqExpression));&lt;br/&gt;
            mc.Fields = Fields.Include(fieldNames);&lt;br/&gt;
            return mc.AsQueryable();&lt;/p&gt;

&lt;p&gt;And although it works, and I was initially excited, it clearly isn&apos;t&lt;br/&gt;
translating that field expression to the Mongo. It&apos;s still fetching the&lt;br/&gt;
whole document but I only get back the fieldNames I asked for. Which makes&lt;br/&gt;
me wonder if a MongoCursor works the way I&apos;d expected. I would have thought&lt;br/&gt;
that setting the Fields property on the cursor would have constructed the&lt;br/&gt;
appropriate query but it must be doing this in the driver?&lt;/p&gt;

</comment>
                            <comment id="211167" author="craiggwilson" created="Mon, 10 Dec 2012 16:39:19 +0000"  >&lt;p&gt;No, it&apos;s not that simple, although that would be nice. There is currently no workaround for pulling back only required fields in a Linq query.  It is a problem with sucking the mapping information out the BsonClassMaps and applying them to another class, for instance, an anonymous class.  This transference is rather difficult when stuff like default values start to occur.  By making the class maps and member maps so flexible and feature rich, it caused supporting pulling back only the required fields to be especially difficult.  &lt;/p&gt;

&lt;p&gt;So, my apologies, but there is no workaround.  I&apos;ll get linq to aggregation done soon which will encompass this functionality and all will be right with the world.&lt;/p&gt;</comment>
                            <comment id="211157" author="daniel.sinclair@nupe.com" created="Mon, 10 Dec 2012 16:32:31 +0000"  >&lt;p&gt;Oh wait, is it as simple as using a Mongo Cursor (instead of Collection.AsQueryable()) and then calling AsQueryable() on the cursor?&lt;/p&gt;</comment>
                            <comment id="211155" author="daniel.sinclair@nupe.com" created="Mon, 10 Dec 2012 16:29:55 +0000"  >&lt;p&gt;Sorry, bad terminology. I&apos;m just trying to do a Fields.Include() with my&lt;br/&gt;
query. I can a do this on MongoCursor obviously, but I&apos;m trying to see&lt;br/&gt;
where I can inject similar functionality into the query stream when I&apos;m&lt;br/&gt;
using LinqExtensionMethods.AsQueryable() as per my Repository.&lt;/p&gt;

&lt;p&gt;Basically, I&apos;m just trying to bring back only those fields I ask for, NOT&lt;br/&gt;
the whole document. So it&apos;s a Projection really I guess, but a field filter&lt;br/&gt;
is how I was thinking about it.&lt;/p&gt;

</comment>
                            <comment id="211143" author="craiggwilson" created="Mon, 10 Dec 2012 16:23:35 +0000"  >&lt;p&gt;This ticket is about projections, not filters.  Could you clarify what you mean by filters?  Perhaps some sample code would help as well showing what you want to do...&lt;/p&gt;</comment>
                            <comment id="211133" author="daniel.sinclair@nupe.com" created="Mon, 10 Dec 2012 16:15:04 +0000"  >&lt;p&gt;Assuming a Repository pattern, can you think of a workaround in the iterim?&lt;br/&gt;
Is there a good place to inject the necessary filters into the query?&lt;/p&gt;

&lt;p&gt;I&apos;ve done this for a single document because I used a MongoCursor, but I&apos;d&lt;br/&gt;
like to do this with AsQueryable()&lt;/p&gt;

</comment>
                            <comment id="211121" author="craiggwilson" created="Mon, 10 Dec 2012 16:02:13 +0000"  >&lt;p&gt;Maybe 1.8, but probably not.  I&apos;m currently working on Linq to Aggregation and this particular feature is mostly working, but the rest of the aggregation stuff isn&apos;t finished.  Hence, this will happen when Linq to Aggregation is finished.&lt;/p&gt;</comment>
                            <comment id="211114" author="daniel.sinclair@nupe.com" created="Mon, 10 Dec 2012 15:53:53 +0000"  >&lt;p&gt;Any thoughts on when this feature might make it into a release?&lt;/p&gt;</comment>
                            <comment id="184991" author="craiggwilson" created="Sat, 10 Nov 2012 23:00:58 +0000"  >&lt;p&gt;Implementing Linq to Aggregation will require a generic way to project actual fields, making this ticket relatively trivial or unnecessary once linq to aggregation is complete.&lt;/p&gt;</comment>
                            <comment id="164067" author="craiggwilson" created="Thu, 13 Sep 2012 17:53:44 +0000"  >&lt;p&gt;I think we are saying the same thing.  When a projection happens, then &quot;ISupportInitialze&quot; will not be run because it doesn&apos;t apply.  But to accomplish that requires a different container to project out of rather than the mapped class (which might have some dependencies on ISupportInitialize to work correctly).  Therefore, we have to find the fields needed for projection and then rewrite the expression trees to deserialize a mapped member into a different container than was originally intended (the mapped class), i.e. copying the serialization information for that member onto a different member.&lt;/p&gt;

&lt;p&gt;I&apos;ve actually spiked this out, and then went further to attempt supporting SelectMany as well, but that becomes extremely difficult to get right.  Therefore, we&apos;ll probably just support Select to begin with.  However, we are also looking at integrating Aggregation Framework queries into the linq provider, which will probably require a lot of rework and this ticket would probably get absorbed into that rewrite.&lt;/p&gt;</comment>
                            <comment id="164061" author="zaidmasud" created="Thu, 13 Sep 2012 17:44:24 +0000"  >&lt;p&gt;Pardon my ignorance, but if a .Select clause is specified, is there really no way to bypass the class instantiation? I suppose this may be what you are alluding to when you mention container projection?&lt;/p&gt;

&lt;p&gt;We would be able to find the corresponding field names form the class map / elements, construct the query, and then return only the values required in the .Select.&lt;/p&gt;

&lt;p&gt;As a driver user I personally would have no expectation of ISupportInitialize still being supported if I was explicitly specifying a .Select clause.&lt;/p&gt;</comment>
                            <comment id="131978" author="craiggwilson" created="Wed, 13 Jun 2012 18:26:14 +0000"  >&lt;p&gt;FluentMongo did this, yes.  It worked by pulling back only the fields required for the projection, but still instantiated the whole class.  So, if I had a class called Person with a FirstName and LastName property and did a query with a projection only for FirstName, we&apos;d still instantiate the whole Person class and then do a local projection off of that.  It works, but since we support things like ISupportInitialize, then instantiating a class with partial data could prove problematic.  Therefore, we are going to project into some other container and rewrite the projection tree to come from the alternative container.  Much more difficult, but definitely more correct.&lt;/p&gt;</comment>
                            <comment id="131968" author="zaidmasud" created="Wed, 13 Jun 2012 18:12:55 +0000"  >&lt;p&gt;Craig &amp;#8211; am I mistaken in saying that Fluent Mongo did this quite well?&lt;/p&gt;</comment>
                            <comment id="116300" author="craiggwilson" created="Fri, 4 May 2012 11:18:23 +0000"  >&lt;p&gt;Yes, it is a bit misleading that we support select, but still pull back the entire document.  Projections are rather difficult and we are working through the best way of handling them right now.  If you&apos;d like this functionality, please vote it up so we have a feel of the communities need for this support.&lt;/p&gt;</comment>
                            <comment id="116273" author="cpdigger" created="Fri, 4 May 2012 08:19:56 +0000"  >&lt;p&gt;We would like to have the first option ( 1) simple projection)&lt;br/&gt;
In our program we have very large documents (Images) and we want only retrieve the ObjectId&apos;s of the document. &lt;/p&gt;

&lt;p&gt;IQueryable&amp;lt;ObjectId&amp;gt; queryable = collection.AsQueryable&amp;lt;Image&amp;gt;().OrderByDescending(img =&amp;gt; img.Created).Skip(0).Take(15).Select(img =&amp;gt; img._id);&lt;/p&gt;

&lt;p&gt;The above code performs very slow and memory consuming. The problem is that in Projection&amp;lt;TSource, TResult&amp;gt; class the &quot;GetEnumerator()&quot; method don&apos;t call _cursor.SetFields() restriction and the complete document was loaded from the database to the client &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/sad.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt; &lt;/p&gt;

&lt;p&gt;If we implement it directly with MongoCursor the code looks like this : &lt;/p&gt;

&lt;p&gt;MongoCursor&amp;lt;Image&amp;gt; cursor = collection.FindAll();&lt;br/&gt;
cursor.SetSortOrder(SortBy.Descending(&quot;Created&quot;));&lt;br/&gt;
cursor.SetSkip(0);&lt;br/&gt;
cursor.SetLimit(15);&lt;br/&gt;
cursor.SetFields(Fields.Include(&quot;_id&quot;));     // !!! restriction &lt;br/&gt;
foreach (Image item in cursor) yield return item._id;&lt;/p&gt;
</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                        <issuelink>
            <issuekey id="52910">CSHARP-601</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="112050">CSHARP-912</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hs0t9r:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>129181</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>