<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 03:05:14 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-4193] Cursor closed if limit is 1</title>
                <link>https://jira.mongodb.org/browse/SERVER-4193</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;If limit is 1, and batchsize is 0, DBApiLayer.chooseBatchSize will return -1, and the cursor will be closed as a result.&lt;/p&gt;

&lt;p&gt;in DBApiLayer.chooseBatchSize, I see&lt;br/&gt;
        if (res == 1) &lt;/p&gt;
{
            // optimization: use negative batchsize to close cursor
            res = -1;
        }

&lt;p&gt;Code to replicate&lt;br/&gt;
I have 4 entries in the collection&lt;/p&gt;

&lt;p&gt;      DB m = Mongo.connect(new DBAddress(&quot;host&quot;, &quot;dbname&quot;));&lt;/p&gt;

&lt;p&gt;      DBCursor c1 = m.getCollection(&quot;mycoll&quot;).find();&lt;br/&gt;
      int count1 = 0;&lt;br/&gt;
      while (c1.hasNext()) &lt;/p&gt;
{
        c1.next();
        count1++;
      }
&lt;p&gt;      System.out.println(&quot;Count 1 is: &quot; + count1);&lt;/p&gt;

&lt;p&gt;      DBCursor c2 = m.getCollection(&quot;buttons&quot;).find().skip(2).limit(1);&lt;br/&gt;
      int count2 = 0;&lt;br/&gt;
      while (c2.hasNext()) &lt;/p&gt;
{
        c2.next();
        count2++;
      }
&lt;p&gt;      System.out.println(&quot;Count 2 is: &quot; + count2);&lt;/p&gt;

&lt;p&gt;Output:&lt;br/&gt;
Count 1 is: 4&lt;br/&gt;
Count 2 is: 0&lt;/p&gt;</description>
                <environment>any</environment>
        <key id="24363">SERVER-4193</key>
            <summary>Cursor closed if limit is 1</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="5">Cannot Reproduce</resolution>
                                        <assignee username="antoine">Antoine Girbal</assignee>
                                    <reporter username="yalexander">Alex Yakushev</reporter>
                        <labels>
                            <label>cursor</label>
                            <label>query</label>
                    </labels>
                <created>Wed, 2 Nov 2011 03:51:57 +0000</created>
                <updated>Thu, 1 Aug 2019 17:27:29 +0000</updated>
                            <resolved>Mon, 30 Apr 2012 02:10:26 +0000</resolved>
                                                                    <component>Sharding</component>
                                        <votes>6</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="114719" author="antoine" created="Mon, 30 Apr 2012 02:08:48 +0000"  >&lt;p&gt;tried again, could not reproduce issue through Java driver with mongo 2.0.2.&lt;br/&gt;
Are you still seeing issue with more recent mongo?&lt;br/&gt;
In theory the java optimization is good to keep.&lt;/p&gt;</comment>
                            <comment id="69654" author="spencer" created="Tue, 29 Nov 2011 22:20:00 +0000"  >&lt;p&gt;I could not reproduce this in the shell or with pymongo, and given that changing an optimization in the java driver fixed the issue, I think this likely is an issue with the java driver, as was originally expected. Antoine, could you take another look and see if you can reproduce it on a sharded system?&lt;/p&gt;</comment>
                            <comment id="64624" author="yalexander" created="Fri, 4 Nov 2011 00:50:33 +0000"  >&lt;p&gt;Server version 1.8.4 has the same problem&lt;/p&gt;</comment>
                            <comment id="64311" author="yalexander" created="Wed, 2 Nov 2011 19:30:14 +0000"  >&lt;p&gt;Removing the optimization that I mentioned in the description from DBApiLayer.chooseBatchSize seems to fix the issue.&lt;/p&gt;</comment>
                            <comment id="64299" author="yalexander" created="Wed, 2 Nov 2011 19:00:11 +0000"  >&lt;p&gt;Server version is 1.8.3&lt;/p&gt;</comment>
                            <comment id="64156" author="scotthernandez" created="Wed, 2 Nov 2011 09:51:54 +0000"  >&lt;p&gt;What server version are you using? This probably has nothing to do with java.&lt;/p&gt;</comment>
                            <comment id="64149" author="yalexander" created="Wed, 2 Nov 2011 08:54:55 +0000"  >&lt;p&gt;Just discovered that the bug shows up only for sharded collections&lt;br/&gt;
Shell commands always work correctly.&lt;/p&gt;

&lt;p&gt;&amp;gt; db.runCommand(&lt;/p&gt;
{enablesharding: &quot;alex-test&quot;}
&lt;p&gt;)&lt;/p&gt;
{ &quot;ok&quot; : 1 }
&lt;p&gt;&amp;gt; db.runCommand({shardcollection:&quot;alex-test.buttons&quot;, key: {_id:1}})&lt;/p&gt;
{ &quot;collectionsharded&quot; : &quot;alex-test.buttons&quot;, &quot;ok&quot; : 1 }
&lt;p&gt;&amp;gt; use alex-test&lt;br/&gt;
switched to db alex-test&lt;br/&gt;
&amp;gt; db.buttons.find()&lt;/p&gt;
{ &quot;_id&quot; : ObjectId(&quot;4eb1025141dadce09bc24fb0&quot;), &quot;a&quot; : 1 }
{ &quot;_id&quot; : ObjectId(&quot;4eb1025441dadce09bc24fb1&quot;), &quot;a&quot; : 2 }
{ &quot;_id&quot; : ObjectId(&quot;4eb1025641dadce09bc24fb2&quot;), &quot;a&quot; : 3 }
{ &quot;_id&quot; : ObjectId(&quot;4eb1025841dadce09bc24fb3&quot;), &quot;a&quot; : 4 }
&lt;p&gt;&amp;gt; db.buttons.find().skip(2).limit(1)&lt;/p&gt;
{ &quot;_id&quot; : ObjectId(&quot;4eb1025641dadce09bc24fb2&quot;), &quot;a&quot; : 3 }

&lt;p&gt;Output of my test java code: (using mongo-2.7.0-rc1.jar)&lt;br/&gt;
Count 1 is: 4&lt;br/&gt;
Count 2 is: 0&lt;/p&gt;


&lt;p&gt;Running the same code on an unsharded collection:&lt;br/&gt;
&amp;gt; db.fingers.find()&lt;/p&gt;
{ &quot;_id&quot; : ObjectId(&quot;4eb103bb41dadce09bc24fb4&quot;), &quot;b&quot; : 1 }
{ &quot;_id&quot; : ObjectId(&quot;4eb103bd41dadce09bc24fb5&quot;), &quot;b&quot; : 2 }
{ &quot;_id&quot; : ObjectId(&quot;4eb103c041dadce09bc24fb6&quot;), &quot;b&quot; : 3 }
{ &quot;_id&quot; : ObjectId(&quot;4eb103c341dadce09bc24fb7&quot;), &quot;b&quot; : 4 }
&lt;p&gt;&amp;gt; db.fingers.find().skip(2).limit(1)&lt;/p&gt;
{ &quot;_id&quot; : ObjectId(&quot;4eb103c041dadce09bc24fb6&quot;), &quot;b&quot; : 3 }

&lt;p&gt;Java output:&lt;br/&gt;
Count 1 is: 4&lt;br/&gt;
Count 2 is: 1&lt;/p&gt;</comment>
                            <comment id="64137" author="antoine" created="Wed, 2 Nov 2011 07:13:14 +0000"  >&lt;p&gt;ok that&apos;s odd, it works fine for me using 2.7 beta driver&lt;br/&gt;
Collection:&lt;br/&gt;
Cursor id=0, ns=test.test, query={ }, numIterated=4, addr=localhost:27001&lt;br/&gt;
{ &quot;_id&quot; : &lt;/p&gt;
{ &quot;$oid&quot; : &quot;4eb0d931276e8a923b13aceb&quot;}
&lt;p&gt; , &quot;a&quot; : 1.0}&lt;br/&gt;
{ &quot;_id&quot; : &lt;/p&gt;
{ &quot;$oid&quot; : &quot;4eb0d932276e8a923b13acec&quot;}
&lt;p&gt; , &quot;a&quot; : 1.0}&lt;br/&gt;
{ &quot;_id&quot; : &lt;/p&gt;
{ &quot;$oid&quot; : &quot;4eb0d932276e8a923b13aced&quot;}
&lt;p&gt; , &quot;a&quot; : 1.0}&lt;br/&gt;
{ &quot;_id&quot; : &lt;/p&gt;
{ &quot;$oid&quot; : &quot;4eb0d933276e8a923b13acee&quot;}
&lt;p&gt; , &quot;a&quot; : 1.0}&lt;/p&gt;

&lt;p&gt;If I query with your options:&lt;br/&gt;
Cursor id=0, ns=test.test, query={ }, numIterated=1, skip=2, limit=1, addr=localhost:27001&lt;br/&gt;
{ &quot;_id&quot; : &lt;/p&gt;
{ &quot;$oid&quot; : &quot;4eb0d932276e8a923b13aced&quot;}
&lt;p&gt; , &quot;a&quot; : 1.0}&lt;/p&gt;

&lt;p&gt;could you try with the driver from git HEAD?&lt;br/&gt;
could you display result of both db.buttons.find() and db.buttons.find().skip(2).limit(1) from shell?&lt;/p&gt;</comment>
                            <comment id="64133" author="yalexander" created="Wed, 2 Nov 2011 06:50:32 +0000"  >&lt;p&gt;I tried to change my silly db and collection names when I posted this example. Alas, now my secret is out, I was querying the &quot;buttons&quot; collection in both cases.&lt;/p&gt;

&lt;p&gt;It works when skip =0. With skip &amp;gt;0, it returns an empty cursor.&lt;/p&gt;</comment>
                            <comment id="64124" author="antoine" created="Wed, 2 Nov 2011 05:49:36 +0000"  >&lt;p&gt;I am not seeing this bug.&lt;br/&gt;
In your test, the 2nd find() queries a different collection, maybe there is nothing in it?&lt;br/&gt;
limit(1) is optimized to limit(-1) since a single doc always fits in a batch, and cursor should be closed.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>10.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Wed, 2 Nov 2011 05:49:36 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        11 years, 42 weeks, 3 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>ian.boros@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            11 years, 42 weeks, 3 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_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10026"><![CDATA[ALL]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>yalexander</customfieldvalue>
            <customfieldvalue>antoine</customfieldvalue>
            <customfieldvalue>scotthernandez</customfieldvalue>
            <customfieldvalue>spencer@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hromof:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>23334</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_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</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|hrovmf:</customfieldvalue>

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