<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:54 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-461] Create Linq + MongoCursor query generation</title>
                <link>https://jira.mongodb.org/browse/CSHARP-461</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Problem:&lt;br/&gt;
1) I create IMongoQuery myQuery = some stuff.&lt;br/&gt;
2) I create IQueryable expresion = myCollection.Find(myQuery).AsQueryable&lt;br/&gt;
3) Apply some additional condition: expresion.Where(x =&amp;gt; x.SomeProperty=someValue)&lt;br/&gt;
4) Execute it.&lt;/p&gt;

&lt;p&gt;Execution:&lt;br/&gt;
1) MongoCursor executed myQuery part.&lt;br/&gt;
2) Via Linq-to-Object &quot;Where&quot; condition applied to MongoCursor result in memory &lt;br/&gt;
So I got two queries - first on the server and the second in memory &lt;/p&gt;

&lt;p&gt;Expected:&lt;br/&gt;
All expression must be executed like a single query on the server side.&lt;/p&gt;





</description>
                <environment></environment>
        <key id="37713">CSHARP-461</key>
            <summary>Create Linq + MongoCursor query generation</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</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="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="gfx00">Brian</reporter>
                        <labels>
                    </labels>
                <created>Thu, 3 May 2012 05:02:42 +0000</created>
                <updated>Thu, 20 Mar 2014 16:39:19 +0000</updated>
                            <resolved>Thu, 3 May 2012 05:28:14 +0000</resolved>
                                    <version>1.4.2</version>
                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="261531" author="craiggwilson" created="Sat, 9 Feb 2013 01:35:44 +0000"  >&lt;p&gt;We are doing some similar things like explain, withindex, and batch size.  It wouldn&apos;t be difficult to put in, but it would get deprecated relatively quickly which presents the problem.  We don&apos;t really want to introduce something for a release only to pull it the next release.  &lt;/p&gt;

&lt;p&gt;But it&apos;s a good suggestion...  We&apos;ll discuss it.&lt;/p&gt;</comment>
                            <comment id="261527" author="daniel.sinclair@nupe.com" created="Sat, 9 Feb 2013 01:29:40 +0000"  >&lt;p&gt;It wouldn&apos;t be elegant, but wouldn&apos;t this be more quickly introduced for the short-term by putting a call to SetFields inside MongoDB.Driver.Linq.SelectQuery.Execute() ? Similar to _take and _limit. Obviously you&apos;d need a hacky way to configure those fields, probably an AsQueryable overload.&lt;/p&gt;

&lt;p&gt;Alternatively, what about some way of injecting properties onto the cursor that the Linq query will end up using?&lt;/p&gt;</comment>
                            <comment id="261171" author="craiggwilson" created="Fri, 8 Feb 2013 18:50:39 +0000"  >&lt;p&gt;We don&apos;t have control over the &quot;AsQueryable&quot; coming off the MongoCursor as that is a System.Linq extension method.  We used AsQueryable for our method name on MongoCollection because it is the generally accepted name.  In version 2.0, we are looking to make some changes around MongoCursor to hopefully alleviate this problem.&lt;/p&gt;

&lt;p&gt;Currently, if you are looking to trim the field list down, you simply can&apos;t use linq.  That seems to be your impetus for your request.  However, we are working on rewriting the linq provider and part of the rewrite is to bake support in for field limiting.  You can track the progress in &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-456&quot; title=&quot;Support linq projections to only pull back referenced fields.&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-456&quot;&gt;&lt;del&gt;CSHARP-456&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;</comment>
                            <comment id="261150" author="daniel.sinclair@nupe.com" created="Fri, 8 Feb 2013 18:25:40 +0000"  >&lt;p&gt;How do you do field restriction with linq? Or how can I get one of these IQueryable interfaces from a MongoCursor?&lt;/p&gt;

&lt;p&gt;I ran into this problem and it&apos;s been baffling me for the last 36 hours why my queries aren&apos;t going through to the database. Again, I was calling System.Linq.Queryable.AsQueryable() on the MongoCursor rather than MongoDB.Driver.Linq.LinqExtensionMethods.AsQueryable() on the MongoCollection. This is a real gotcha as I think I&apos;ve made this mistake before. It&apos;s easily done as they&apos;re both identically named extension methods and since they both return an IQueryable&amp;lt;&amp;gt;.&lt;/p&gt;

&lt;p&gt;I think it&apos;s an unfortunate confusion, and I&apos;d rather have seen it named something else, but I just need to make a note somewhere not to fall into this trap again. Unfortunately, you can&apos;t easily guard against it if you have both namespaces included in your file. I might just try being explicit (var iq = MongoDB.Driver.Linq.LinqExtensionMethods.AsQueryable(col)).&lt;/p&gt;

&lt;p&gt;So the reason I was using MongoCursor in the first place was so I can use the .Fields property. AsQueryable() was then the trap I laid for myself.&lt;/p&gt;

&lt;p&gt;So is it possible to combine a cursor with the linq methods? Or can use do field restriction with the linq model?&lt;/p&gt;</comment>
                            <comment id="115888" author="gfx00" created="Thu, 3 May 2012 06:15:38 +0000"  >&lt;p&gt;Combininig could be good in case when you need to create some search engine. With Query methods it could be done easily but then you want to apply some common conditions but you don&apos;t want to use &quot;magic string&quot; to do this. So you combine your query with Linq.&lt;/p&gt;

&lt;p&gt;Thank you. Inject is that what I need.&lt;/p&gt;</comment>
                            <comment id="115883" author="rstam" created="Thu, 3 May 2012 05:27:32 +0000"  >&lt;p&gt;The Find method of MongoCollection&amp;lt;T&amp;gt; returns a MongoCursor&amp;lt;T&amp;gt; which in turn implements IEnumerable&amp;lt;T&amp;gt;, at which point you are committed to evaluating the rest of the LINQ queries client side.&lt;/p&gt;

&lt;p&gt;Usually you would write your query entirely in LINQ. It is unusual to mix a regular MongoDB query with a LINQ query. You probably should write your entire query in LINQ, but if you really want to mix the models you can use the Inject method to inject the lower level MongoDB query into the higher level LINQ query, as in:&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 class C&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;    public ObjectId 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;    public int X;&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;    public int Y;&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;&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;var mongoQuery = Query.GT(&quot;X&quot;, 0);&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 linqQuery = collection.AsQueryable&amp;lt;C&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;    .Where(c =&amp;gt; mongoQuery.Inject())&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;    .Where(c =&amp;gt; c.Y &amp;gt; 0);&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;Note: to use LINQ to Mongo you call AsQueryable on the collection, not on the cursor.&lt;/p&gt;
</comment>
                    </comments>
                    <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|hrh7lr:</customfieldvalue>

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