<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 05:58:21 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-63667] .find() returning multiple instances of the same document</title>
                <link>https://jira.mongodb.org/browse/SERVER-63667</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Mongo appears to be returning duplicate documents for the same query, i.e. it returns more documents than there are unique&#160;{{_id}}s in the returned documents:&lt;br/&gt;
lobby-brain&amp;gt; count_iterated = 0; ids = {}&lt;br/&gt;
{}&lt;br/&gt;
lobby-brain&amp;gt; db.the_collection.find({&lt;br/&gt;
    &apos;a_boolean_key&apos;: true &lt;br/&gt;
}).forEach((el) =&amp;gt; {&lt;br/&gt;
    count_iterated += 1; &lt;br/&gt;
    ids&lt;span class=&quot;error&quot;&gt;&amp;#91;el._id&amp;#93;&lt;/span&gt; = (ids&lt;span class=&quot;error&quot;&gt;&amp;#91;el._id&amp;#93;&lt;/span&gt;||0) + 1;&lt;br/&gt;
})&lt;br/&gt;
lobby-brain&amp;gt; count_iterated&lt;br/&gt;
278&lt;br/&gt;
lobby-brain&amp;gt; Object.keys(ids).length&lt;br/&gt;
251&lt;br/&gt;
That is, the number of unique _id returned is 251 &amp;#8211; but there were 278 documents returned by the cursor.&lt;/p&gt;

&lt;p&gt;Investigating further:&lt;br/&gt;
lobby-brain&amp;gt; ids&lt;br/&gt;
{&lt;br/&gt;
  &apos;60cb8cb92c909a974a96a430&apos;: 1,&lt;br/&gt;
  &apos;61114dea1a13c86146729f21&apos;: 1,&lt;br/&gt;
  &apos;6111513a1a13c861467d3dcf&apos;: 1,&lt;br/&gt;
  ...&lt;br/&gt;
  &apos;61114c491a13c861466d39cf&apos;: 2,&lt;br/&gt;
  &apos;61114bcc1a13c861466b9f8e&apos;: 2,&lt;br/&gt;
  ...&lt;br/&gt;
}&lt;br/&gt;
lobby-brain&amp;gt; db.the_collection.find({&lt;br/&gt;
    _id: ObjectId(&quot;61114c491a13c861466d39cf&quot;)&lt;br/&gt;
}).forEach((el) =&amp;gt; print(&quot;foo&quot;));&lt;br/&gt;
foo&lt;/p&gt;

&lt;p&gt;&amp;gt; &lt;br/&gt;
{{}}&lt;/p&gt;

&lt;p&gt;That is, there aren&apos;t actually duplicate documents with the same&#160;&lt;tt&gt;_id&lt;/tt&gt;&#160;-- it&apos;s just an issue with the&#160;&lt;tt&gt;.find()&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;I tried restarting the database, and rebuilding an index involving &apos;a_boolean_key&apos;, with the same results.&lt;/p&gt;

&lt;p&gt;I&apos;ve never seen this before and this seems impossible...&#160;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Version info:&lt;/b&gt;&lt;br/&gt;
Using MongoDB:          5.0.5&lt;br/&gt;
Using Mongosh:          1.0.4&lt;br/&gt;
{{}}&lt;/p&gt;

&lt;p&gt;It is a stand-alone database, no replica set or sharding or anything like that.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Further Info&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;One thing to note is, there is a compound index with a_boolean_key as the first index, and a datetime field as the second. The boolean key is rarely updated on the database (~once/day), but the datetime field is frequently updated.&lt;/p&gt;

&lt;p&gt;Maybe these updates are causing the duplicate return values?&lt;/p&gt;</description>
                <environment>archlinux , 128 GB RAM server</environment>
        <key id="1983579">SERVER-63667</key>
            <summary>.find() returning multiple instances of the same document</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="13202">Works as Designed</resolution>
                                        <assignee username="backlog-server-execution">Backlog - Storage Execution Team</assignee>
                                    <reporter username="csaftoiu@gmail.com">Claudiu Saftoiu</reporter>
                        <labels>
                            <label>duplicates</label>
                            <label>query</label>
                    </labels>
                <created>Tue, 15 Feb 2022 11:41:35 +0000</created>
                <updated>Fri, 27 Oct 2023 13:52:07 +0000</updated>
                            <resolved>Thu, 24 Feb 2022 16:48:08 +0000</resolved>
                                    <version>5.0.5</version>
                                                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="4356692" author="JIRAUSER1269889" created="Tue, 15 Feb 2022 17:36:10 +0000"  >&lt;p&gt;Understood!&#160;&lt;/p&gt;

&lt;p&gt;In this case `a_boolean_key` wasn&apos;t updated frequently, but the 2nd field on the compound index was updated frequently &#8211; so I&apos;m presuming the same applies. Good to learn something new!&lt;/p&gt;</comment>
                            <comment id="4356610" author="louis.williams" created="Tue, 15 Feb 2022 17:15:53 +0000"  >&lt;p&gt;Hi, &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=csaftoiu%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;csaftoiu@gmail.com&quot;&gt;csaftoiu@gmail.com&lt;/a&gt;, if you perform an index scan that is concurrent with updates, it is possible to see duplicate _id values.&lt;/p&gt;

&lt;p&gt;If you modify a document&apos;s `a_boolean_key`, the new key will change its position in the sorted index. It could move before or after the current position of your cursor. If you encounter this race, you will see the same document twice, but with different values for its `a_boolean_key`.&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>2.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_12751" key="com.atlassian.jira.plugin.system.customfieldtypes:multiselect">
                        <customfieldname>Assigned Teams</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="25136"><![CDATA[Storage Execution]]></customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 15 Feb 2022 17:15:53 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        1 year, 51 weeks, 1 day 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>
                            1 year, 51 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>backlog-server-execution</customfieldvalue>
            <customfieldvalue>csaftoiu@gmail.com</customfieldvalue>
            <customfieldvalue>louis.williams@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i0k7pb:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</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|i0jtun:</customfieldvalue>

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