<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:03:02 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>[DOCS-11534] Docs for SERVER-3645: Sharded collection counts (on primary) can report too many results</title>
                <link>https://jira.mongodb.org/browse/DOCS-11534</link>
                <project id="10380" key="DOCS">Documentation</project>
                    <description>&lt;h1&gt;&lt;a name=&quot;DocumentationRequestSummary%3A&quot;&gt;&lt;/a&gt;Documentation Request Summary:&lt;/h1&gt;

&lt;p&gt;The page below will need to be updated:&lt;br/&gt;
 &lt;a href=&quot;https://docs.mongodb.com/manual/reference/command/count/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.com/manual/reference/command/count/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following paragraphs should be changed:&lt;br/&gt;
 ---------------------------------------------------&lt;br/&gt;
 On a sharded cluster, count can result in an inaccurate count if orphaned documents exist or if a chunk migration is in progress.&lt;/p&gt;

&lt;p&gt;To avoid these situations, on a sharded cluster, use the $group stage of the db.collection.aggregate() method to $sum the documents. For example, the following operation counts the documents in a collection:&lt;br/&gt;
 ---------------------------------------------------&lt;/p&gt;

&lt;p&gt;The new behavior is that, when running a sharded cluster, a &lt;em&gt;fast&lt;/em&gt; count may return inaccurate results. A count() with a predicate will not (as of 4.0). See the &quot;Behavior of &quot;fast count&quot; and non-&quot;fast count&quot; in the description of the ticket. If you have any questions feel free to slack/email/comment on a ticket!&lt;/p&gt;
&lt;h1&gt;&lt;a name=&quot;%C2%A0&quot;&gt;&lt;/a&gt;&#160;&lt;/h1&gt;
&lt;h2&gt;&lt;a name=&quot;Scopeofchanges%3A&quot;&gt;&lt;/a&gt;Scope of changes:&lt;/h2&gt;
&lt;ul&gt;
	&lt;li&gt;count (various)&lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;&lt;a name=&quot;Impacttootherdocsoutsideofthisproduct%3A&quot;&gt;&lt;/a&gt;Impact to other docs outside of this product:&lt;/h2&gt;

&lt;p&gt;none&lt;br/&gt;
&#160;&lt;/p&gt;
&lt;h2&gt;&lt;a name=&quot;MVP%3A&quot;&gt;&lt;/a&gt;MVP:&lt;/h2&gt;
&lt;h2&gt;&lt;a name=&quot;Resources%3A&quot;&gt;&lt;/a&gt;Resources:&lt;/h2&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;h2&gt;&lt;a name=&quot;EngineeringTicketDescription%3A&quot;&gt;&lt;/a&gt;Engineering Ticket Description:&lt;/h2&gt;
&lt;h2&gt;&lt;a name=&quot;Summary&quot;&gt;&lt;/a&gt;Summary&lt;/h2&gt;

&lt;p&gt;Count does not filter out unowned (orphaned) documents and can therefore report larger values than one will find via a normal query, or using itcount() in the shell.&lt;/p&gt;
&lt;h3&gt;&lt;a name=&quot;Causes&quot;&gt;&lt;/a&gt;Causes&lt;/h3&gt;

&lt;p&gt;The following conditions can lead to counts being off:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Active migrations&lt;/li&gt;
	&lt;li&gt;Orphaned documents (left from failed migrations)&lt;/li&gt;
	&lt;li&gt;Non-Primary read preferences (see &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-5931&quot; title=&quot;Secondary reads in sharded clusters need stronger consistency&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-5931&quot;&gt;&lt;del&gt;SERVER-5931&lt;/del&gt;&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;&lt;a name=&quot;Workaround&quot;&gt;&lt;/a&gt;Workaround&lt;/h2&gt;

&lt;p&gt;A workaround to get accurate counts is to ensure all migrations have been &lt;a href=&quot;http://docs.mongodb.org/manual/reference/command/cleanupOrphaned/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;cleaned up&lt;/a&gt; and no migrations are active. To query non-primaries you must also ensure that there is no replication lag including any migration data, in addition to the above requirements.&lt;/p&gt;
&lt;h3&gt;&lt;a name=&quot;NonPrimaryReads&quot;&gt;&lt;/a&gt;Non-Primary Reads&lt;/h3&gt;

&lt;p&gt;For issues with counts/reads from non-primaries please see &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-5931&quot; title=&quot;Secondary reads in sharded clusters need stronger consistency&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-5931&quot;&gt;&lt;del&gt;SERVER-5931&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name=&quot;Behaviorof%22fastcount%22andnon%22fastcount%22&quot;&gt;&lt;/a&gt;Behavior of &quot;fast count&quot; and non-&quot;fast count&quot;&lt;/h3&gt;

&lt;p&gt;A &quot;fast count&quot; is a count run without a predicate. It is &quot;fast&quot; because the implementation only reads the metadata, without fetching any documents.&lt;/p&gt;

&lt;p&gt;The problem of &lt;tt&gt;count()&lt;/tt&gt; reporting inaccurate results has been fixed for non-&quot;fast counts,&quot; that is, starting in 4.0, counts which are run with a predicate are accurate when run on sharded clusters. &quot;Fast counts&quot; (&lt;tt&gt;count()&lt;/tt&gt; run without a predicate) may still report too many documents (see &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-33753&quot; title=&quot;count without predicate should be sharding aware&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-33753&quot;&gt;SERVER-33753&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;In general, if one needs an accurate count of how many documents are in a collection, we do not recommend using the &lt;tt&gt;count&lt;/tt&gt; command. Instead, we suggest using the &lt;tt&gt;$count&lt;/tt&gt; aggregation stage, like this:&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.aggregate([{$count: &quot;nDocs&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;
&lt;p&gt;See &lt;a href=&quot;https://docs.mongodb.com/manual/reference/operator/aggregation/count/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;the docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For users who need the performance of &quot;fast count&quot;, and are okay with approximate results, we suggest using $collStats instead of the count command:&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.matrices.aggregate( [ { $collStats: { count: { } } } ] )&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</description>
                <environment></environment>
        <key id="520997">DOCS-11534</key>
            <summary>Docs for SERVER-3645: Sharded collection counts (on primary) can report too many results</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="13201">Fixed</resolution>
                                        <assignee username="kay.kim@mongodb.com">Kay Kim</assignee>
                                    <reporter username="kay.kim@mongodb.com">Kay Kim</reporter>
                        <labels>
                    </labels>
                <created>Tue, 3 Apr 2018 04:15:42 +0000</created>
                <updated>Sun, 29 Oct 2023 13:58:06 +0000</updated>
                            <resolved>Thu, 17 May 2018 16:04:49 +0000</resolved>
                                                    <fixVersion>3.7.4</fixVersion>
                                        <due></due>
                            <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="1899788" author="xgen-internal-githook" created="Wed, 23 May 2018 17:46:55 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;username&apos;: &apos;kay-kim&apos;, &apos;name&apos;: &apos;kay&apos;, &apos;email&apos;: &apos;kay.kim@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-11534&quot; title=&quot;Docs for SERVER-3645: Sharded collection counts (on primary) can report too many results&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-11534&quot;&gt;&lt;del&gt;DOCS-11534&lt;/del&gt;&lt;/a&gt;: count and fast count&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/4d3fda249f43733239b8eb4d59e119b665f3dbb1&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/4d3fda249f43733239b8eb4d59e119b665f3dbb1&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1894131" author="xgen-internal-githook" created="Thu, 17 May 2018 16:04:33 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;email&apos;: &apos;kay.kim@10gen.com&apos;, &apos;username&apos;: &apos;kay-kim&apos;, &apos;name&apos;: &apos;kay&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-11534&quot; title=&quot;Docs for SERVER-3645: Sharded collection counts (on primary) can report too many results&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-11534&quot;&gt;&lt;del&gt;DOCS-11534&lt;/del&gt;&lt;/a&gt;: count and sharded clusters&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/f5dc508a14dfce31ac5df10a82a5913e900d0f35&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/f5dc508a14dfce31ac5df10a82a5913e900d0f35&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10320">
                    <name>Documented</name>
                                            <outwardlinks description="documents">
                                        <issuelink>
            <issuekey id="21174">SERVER-3645</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>2.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_13552" key="com.go2group.jira.plugin.crm:crm_generic_field">
                        <customfieldname>Case</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[[5002K00000gm1k1QAA]]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Thu, 17 May 2018 16:04:33 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        5 years, 38 weeks 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_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>DOCS-11003</customfieldvalue>
                        </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>
                            5 years, 38 weeks ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>xgen-internal-githook</customfieldvalue>
            <customfieldvalue>kay.kim@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|htu7lj:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|htlglb:</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_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|httttr:</customfieldvalue>

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