<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:59:04 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>[SERVER-2130] Ability to use Limit() with Distinct()</title>
                <link>https://jira.mongodb.org/browse/SERVER-2130</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Ability to use Limit() with Distinct()... or any of the cursor methods for the matter (sort, count, skip, etc. although limit has the biggest impact).&lt;/p&gt;

&lt;p&gt;Apparently there is no simple way to currently perform the following SQL query:&lt;/p&gt;

&lt;p&gt;SELECT DISTINCT(myField) FROM myTable WHERE x = y LIMIT(20)&lt;/p&gt;

&lt;p&gt;The current Distinct() implementation only allows for bringing back ALL distinct values in the collection or matching a query, but there is no way to limit these results. This would be very convenient and there are many use cases.&lt;/p&gt;</description>
                <environment>all</environment>
        <key id="13767">SERVER-2130</key>
            <summary>Ability to use Limit() with Distinct()</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="backlog-query-optimization">Backlog - Query Optimization</assignee>
                                    <reporter username="sym3tri">Ed Rooth</reporter>
                        <labels>
                            <label>query_triage</label>
                    </labels>
                <created>Mon, 22 Nov 2010 03:20:06 +0000</created>
                <updated>Thu, 6 Apr 2023 16:24:30 +0000</updated>
                                                                            <component>Querying</component>
                                        <votes>53</votes>
                                    <watches>46</watches>
                                                                                                                <comments>
                            <comment id="3478031" author="JIRAUSER1257520" created="Thu, 5 Nov 2020 18:47:08 +0000"  >&lt;p&gt;Is there any progress on this feature? Aggregate is an okay workaround however it&apos;s not ideal, hoping to be able to apply limit with distinct&lt;/p&gt;</comment>
                            <comment id="2312868" author="asya" created="Thu, 4 Jul 2019 14:50:50 +0000"  >&lt;p&gt;4.2 has the fix &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-9507&quot; title=&quot;Optimize $sort+$group+$first pipeline to avoid full index scan&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-9507&quot;&gt;&lt;del&gt;SERVER-9507&lt;/del&gt;&lt;/a&gt; - while it is not a direct solution to this problem, it will use an &#160;efficient DISTINCT_SCAN of the index while doing $group: on an indexed field.&lt;/p&gt;

&lt;p&gt;The real solution for $limit after $group being optimized will be &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-4507&quot; title=&quot;aggregation:  optimize $group to take advantage of sorted sequences&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-4507&quot;&gt;SERVER-4507&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="1920072" author="asya" created="Wed, 13 Jun 2018 20:44:10 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=micseydel&quot; class=&quot;user-hover&quot; rel=&quot;micseydel&quot;&gt;micseydel&lt;/a&gt; we still have plans to provide simpler syntax (and more performant execution) for what is requested here.&lt;/p&gt;

&lt;p&gt;The two linked SERVER tickets describe the work that we hope to schedule in the future.&lt;/p&gt;</comment>
                            <comment id="1919072" author="micseydel" created="Tue, 12 Jun 2018 23:25:31 +0000"  >&lt;p&gt;Is this still a possible feature? Given how long it&apos;s been open, and a &quot;workaround&quot; being provided, I would imagine this should be closed a Won&apos;t Complete.&lt;/p&gt;</comment>
                            <comment id="1623271" author="JIRAUSER1257116" created="Mon, 17 Jul 2017 07:36:12 +0000"  >&lt;p&gt;If you have 7 mil documents and you perform the collection.aggregate(&lt;span class=&quot;error&quot;&gt;&amp;#91;{$group : {_id : &amp;quot;$field&amp;quot;}},{$limit:1}&amp;#93;&lt;/span&gt;) you will wait ~20 seconds. This is not ok. If i need a set of &quot;field&quot;  values having the cardinal 1, i shouldn&apos;t wait that long.&lt;/p&gt;</comment>
                            <comment id="1181063" author="asya" created="Mon, 22 Feb 2016 21:03:46 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=axom&quot; class=&quot;user-hover&quot; rel=&quot;axom&quot;&gt;axom&lt;/a&gt; you absolutely correct, I will fix or remove mine. &lt;/p&gt;</comment>
                            <comment id="1180999" author="axom" created="Mon, 22 Feb 2016 19:58:16 +0000"  >&lt;p&gt;Asya&apos;s suggestion may have worked in a past iteration of mongo, but at least currently you will need to adjust the group stage to get the limit to do anything.&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;{$group: {_id: &quot;$myField&quot;}}&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="781955" author="asya" created="Tue, 9 Dec 2014 17:19:02 +0000"  >&lt;p&gt;This can be done using aggregation framework as&lt;/p&gt;

&lt;p&gt;&lt;b&gt;edited&lt;/b&gt;&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;db.collection.aggregate([{$match:{&amp;lt;your-filter&amp;gt;}}, {$group:{_id:&quot;$myField&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;/* optionally */ {$sort:{_id:1}} /* or by another field that was preserved in $group stage */&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;{$limit:20}])&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="781580" author="mozillazg" created="Tue, 9 Dec 2014 06:17:19 +0000"  >&lt;p&gt;Is there any news about this feature request?&lt;/p&gt;</comment>
                            <comment id="761785" author="ivan.fioravanti@4ward.it" created="Tue, 11 Nov 2014 23:26:25 +0000"  >&lt;p&gt;Any news on this feature request? It is quite useful in some scenario.&lt;/p&gt;</comment>
                            <comment id="501340" author="bgsosh@gmail.com" created="Wed, 19 Feb 2014 11:10:35 +0000"  >&lt;p&gt;Very surprised I couldn&apos;t do this.  Last comment Sept 2012! Any update?&lt;/p&gt;</comment>
                            <comment id="164990" author="ian@10gen.com" created="Mon, 17 Sep 2012 14:30:45 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jhgustafsson&quot; class=&quot;user-hover&quot; rel=&quot;jhgustafsson&quot;&gt;jhgustafsson&lt;/a&gt; this has not been completed yet, and it isn&apos;t scheduled for the upcoming 2.4 release.  We will re-evaluate this for upcoming releases as we begin preparing them.&lt;/p&gt;</comment>
                            <comment id="164786" author="jhgustafsson" created="Sun, 16 Sep 2012 08:21:26 +0000"  >&lt;p&gt;Is this feature resolved yet? If not, is it planned for any version? (and is the PHP-driver likely to be updated soon after?)&lt;/p&gt;</comment>
                            <comment id="58190" author="dominik" created="Mon, 3 Oct 2011 14:06:48 +0000"  >&lt;p&gt;Sort() with Distinct() could also be very useful, for example in the following case:&lt;/p&gt;

&lt;p&gt;Email messages and attachments (attachments saved in an array inside the email message document).&lt;br/&gt;
Getting the distinct list of attachment names ordered by message date would ask for the distinct on &apos;attachment name&apos;, but with a sort on &apos;message date&apos;.&lt;/p&gt;</comment>
                            <comment id="28960" author="gerhardb" created="Thu, 14 Apr 2011 15:02:27 +0000"  >&lt;p&gt;Using distinct with sort would be my biggest hope for 1.9.0 apart from limit.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="302750">SERVER-25184</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="26715">SERVER-4507</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="351626">SERVER-27915</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="73561">SERVER-9507</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>15.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_12751" key="com.atlassian.jira.plugin.system.customfieldtypes:multiselect">
                        <customfieldname>Assigned Teams</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="25126"><![CDATA[Query Optimization]]></customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Thu, 14 Apr 2011 15:02:27 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        3 years, 13 weeks, 6 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>luke.bonanomi@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            3 years, 13 weeks, 6 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>alexandru.bt@gmail.com</customfieldvalue>
            <customfieldvalue>asya.kamsky@mongodb.com</customfieldvalue>
            <customfieldvalue>backlog-query-optimization</customfieldvalue>
            <customfieldvalue>axom</customfieldvalue>
            <customfieldvalue>devin.matte@datadoghq.com</customfieldvalue>
            <customfieldvalue>dominik</customfieldvalue>
            <customfieldvalue>sym3tri</customfieldvalue>
            <customfieldvalue>gerhardb</customfieldvalue>
            <customfieldvalue>ian@mongodb.com</customfieldvalue>
            <customfieldvalue>ivan.fioravanti@4ward.it</customfieldvalue>
            <customfieldvalue>jhgustafsson</customfieldvalue>
            <customfieldvalue>micseydel</customfieldvalue>
            <customfieldvalue>mozillazg</customfieldvalue>
            <customfieldvalue>bgsosh@gmail.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpb1z:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr2ctb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4733</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hryg9z:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>