<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:52:34 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>[JAVA-563] FindOne with Sort</title>
                <link>https://jira.mongodb.org/browse/JAVA-563</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;In order to do sort on a findOne you have to:&lt;/p&gt;

&lt;p&gt;find(query).limit(1).sort(sortBy).next()&lt;/p&gt;

&lt;p&gt;It would be more convenient to have sort support within the findOne method, for example:&lt;/p&gt;

&lt;p&gt;findOne(query,fields,sort) &lt;/p&gt;

&lt;p&gt;I am using Java but this is likely to apply to many other drivers. &lt;/p&gt;</description>
                <environment></environment>
        <key id="37838">JAVA-563</key>
            <summary>FindOne with Sort</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="steve.briskin">Steve Briskin</assignee>
                                    <reporter username="charris">Chris Harris</reporter>
                        <labels>
                    </labels>
                <created>Fri, 4 May 2012 17:41:22 +0000</created>
                <updated>Wed, 29 Aug 2012 20:08:04 +0000</updated>
                            <resolved>Mon, 2 Jul 2012 21:48:37 +0000</resolved>
                                                    <fixVersion>2.9.0</fixVersion>
                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="158216" author="jeff.yemin" created="Wed, 29 Aug 2012 20:08:04 +0000"  >&lt;p&gt;Closing as part of 2.9.0 release process.&lt;/p&gt;</comment>
                            <comment id="141451" author="auto" created="Tue, 10 Jul 2012 17:58:35 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-06-14T09:50:46-07:00&apos;, u&apos;name&apos;: u&apos;Steve Briskin&apos;, u&apos;email&apos;: u&apos;steve.briskin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-563&quot; title=&quot;FindOne with Sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-563&quot;&gt;&lt;del&gt;JAVA-563&lt;/del&gt;&lt;/a&gt;: refactored queryopbuilder&lt;br/&gt;
Branch: ReadPrefs&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/1f6c5976edcd7661d5529ecdc515dabe0e9044f2&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/1f6c5976edcd7661d5529ecdc515dabe0e9044f2&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="141450" author="auto" created="Tue, 10 Jul 2012 17:58:34 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-06-13T12:43:27-07:00&apos;, u&apos;name&apos;: u&apos;Steve Briskin&apos;, u&apos;email&apos;: u&apos;steve.briskin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-563&quot; title=&quot;FindOne with Sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-563&quot;&gt;&lt;del&gt;JAVA-563&lt;/del&gt;&lt;/a&gt;: added orderby to findOne().  Refactored query construction to be consistent between find() and findOne().&lt;br/&gt;
Branch: ReadPrefs&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/e6198e541bf64305909c1a36ceefbd57b3fe5f55&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/e6198e541bf64305909c1a36ceefbd57b3fe5f55&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="141445" author="auto" created="Tue, 10 Jul 2012 17:58:26 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-06-14T09:50:46-07:00&apos;, u&apos;name&apos;: u&apos;Steve Briskin&apos;, u&apos;email&apos;: u&apos;steve.briskin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-563&quot; title=&quot;FindOne with Sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-563&quot;&gt;&lt;del&gt;JAVA-563&lt;/del&gt;&lt;/a&gt;: refactored queryopbuilder&lt;br/&gt;
Branch: ReadPrefs&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/3ef7a868296af7da9f277e06ce9a0ae99862e02a&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/3ef7a868296af7da9f277e06ce9a0ae99862e02a&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="141444" author="auto" created="Tue, 10 Jul 2012 17:58:25 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-06-13T12:43:27-07:00&apos;, u&apos;email&apos;: u&apos;steve.briskin@10gen.com&apos;, u&apos;name&apos;: u&apos;Steve Briskin&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-563&quot; title=&quot;FindOne with Sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-563&quot;&gt;&lt;del&gt;JAVA-563&lt;/del&gt;&lt;/a&gt;: added orderby to findOne().  Refactored query construction to be consistent between find() and findOne().&lt;br/&gt;
Branch: ReadPrefs&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/83fef69fc3425ccfa166e5c224b9afb277a72dec&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/83fef69fc3425ccfa166e5c224b9afb277a72dec&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="136312" author="auto" created="Mon, 25 Jun 2012 15:50:14 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-06-14T09:50:46-07:00&apos;, u&apos;name&apos;: u&apos;Steve Briskin&apos;, u&apos;email&apos;: u&apos;steve.briskin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-563&quot; title=&quot;FindOne with Sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-563&quot;&gt;&lt;del&gt;JAVA-563&lt;/del&gt;&lt;/a&gt;: refactored queryopbuilder&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/1f6c5976edcd7661d5529ecdc515dabe0e9044f2&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/1f6c5976edcd7661d5529ecdc515dabe0e9044f2&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="136311" author="auto" created="Mon, 25 Jun 2012 15:50:13 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-06-13T12:43:27-07:00&apos;, u&apos;name&apos;: u&apos;Steve Briskin&apos;, u&apos;email&apos;: u&apos;steve.briskin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-563&quot; title=&quot;FindOne with Sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-563&quot;&gt;&lt;del&gt;JAVA-563&lt;/del&gt;&lt;/a&gt;: added orderby to findOne().  Refactored query construction to be consistent between find() and findOne().&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/e6198e541bf64305909c1a36ceefbd57b3fe5f55&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/e6198e541bf64305909c1a36ceefbd57b3fe5f55&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="136307" author="auto" created="Mon, 25 Jun 2012 15:50:06 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-06-14T09:50:46-07:00&apos;, u&apos;name&apos;: u&apos;Steve Briskin&apos;, u&apos;email&apos;: u&apos;steve.briskin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-563&quot; title=&quot;FindOne with Sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-563&quot;&gt;&lt;del&gt;JAVA-563&lt;/del&gt;&lt;/a&gt;: refactored queryopbuilder&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/3ef7a868296af7da9f277e06ce9a0ae99862e02a&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/3ef7a868296af7da9f277e06ce9a0ae99862e02a&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="136306" author="auto" created="Mon, 25 Jun 2012 15:50:03 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-06-13T12:43:27-07:00&apos;, u&apos;name&apos;: u&apos;Steve Briskin&apos;, u&apos;email&apos;: u&apos;steve.briskin@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-563&quot; title=&quot;FindOne with Sort&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-563&quot;&gt;&lt;del&gt;JAVA-563&lt;/del&gt;&lt;/a&gt;: added orderby to findOne().  Refactored query construction to be consistent between find() and findOne().&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/83fef69fc3425ccfa166e5c224b9afb277a72dec&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/83fef69fc3425ccfa166e5c224b9afb277a72dec&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="132736" author="jeff.yemin" created="Thu, 14 Jun 2012 17:34:32 +0000"  >&lt;p&gt;We already have overloaded findOne with ReadPreference.  This is following the logical progression of overloaded methods that we already have.  It may be a mistake to have findOne at all on DBCollection, but since we do, this change increases the consistency between DBCursor and DBCollection.&lt;/p&gt;</comment>
                            <comment id="132718" author="scotthernandez" created="Thu, 14 Jun 2012 17:07:12 +0000"  >&lt;p&gt;We should not be expanding the API in this direction. Adding more methods on collection gets complicated and people want even more options for findOne overloads, like readPrefs, sorts, . We should make a method on cursor like oneOrNull/first() or something to special case the findOne case:&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;DBObject dbObj = coll.find(...).sort(...).firstOrNull();&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;next() is bad in this use case because it throws an exception if null/empty.&lt;/p&gt;</comment>
                            <comment id="116438" author="jeff.yemin" created="Fri, 4 May 2012 19:21:19 +0000"  >&lt;p&gt;Yeah, pymongo has &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;  db.foo.find_one({&apos;lastname&apos;: &quot;Yemin&quot;}, sort=[(&apos;field&apos;, 1), (&apos;field&apos;, -1)])&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;Java driver could support something similar, like:&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;  public DBObject findOne(DBObject obj, DBObject fields, DBObject sort);&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>
                    </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|hrghjr:</customfieldvalue>

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