<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:45:58 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>[CSHARP-3680] Migrating obsolete &quot;Count&quot; to new methods has a problematic cost</title>
                <link>https://jira.mongodb.org/browse/CSHARP-3680</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I&apos;m tasked with cleaning up the warnings for our C# Framework 4.8 project and I&apos;m running into difficulties with resolving obsolete warnings for the Mongo Driver.&lt;/p&gt;

&lt;p&gt;The problem is &quot;Count is obsolete. Use CountDocuments&quot; instead. But that&apos;s problematic as `CountDocuments` is slower (see linked Issue &lt;a href=&quot;https://jira.mongodb.org/browse/NODE-1638&quot; title=&quot;countDocuments is slower then count&quot; class=&quot;issue-link&quot; data-issue-key=&quot;NODE-1638&quot;&gt;&lt;del&gt;NODE-1638&lt;/del&gt;&lt;/a&gt;). That&apos;s not an option for us, as we&apos;re already having into performance issues. Thus, like the answer to that issue suggests, we would prefer to use `EstimatedDocumentCount`. But that doesn&apos;t seem to be a drop-in replacement! `EstimatedDocumentCount` doesn&apos;t take a `filter` argument.&lt;/p&gt;

&lt;p&gt;Second problem is that `IFindFluent.Count` is also showing the obsolete warning. But IFindFluent doesn&apos;t even have a `EstimatedDocumentCount` alternative.&lt;/p&gt;

&lt;p&gt;So how do I solve this? We want to update, but don&apos;t want a performance impact. Our customers are already complaining.&lt;/p&gt;

&lt;p&gt;(And I&apos;m not even talking about the &quot;when migrating from Count to CountDocuments the following query operations&#160;must be replaced&quot; part. Breaking changes are high risk for business logic.)&lt;/p&gt;</description>
                <environment></environment>
        <key id="1736432">CSHARP-3680</key>
            <summary>Migrating obsolete &quot;Count&quot; to new methods has a problematic cost</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</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="james.kovacs@mongodb.com">James Kovacs</assignee>
                                    <reporter username="jochem@netwinst.nl">Jochem Bonarius</reporter>
                        <labels>
                    </labels>
                <created>Thu, 20 May 2021 12:29:51 +0000</created>
                <updated>Fri, 27 Oct 2023 13:24:45 +0000</updated>
                            <resolved>Tue, 8 Jun 2021 19:37:11 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>7</watches>
                                                                                                                <comments>
                            <comment id="3867211" author="james.kovacs" created="Tue, 8 Jun 2021 19:37:11 +0000"  >&lt;p&gt;The performance regression between &lt;tt&gt;Count&lt;/tt&gt; and &lt;tt&gt;CountDocuments&lt;/tt&gt; originates from the server and the driver does not introduce any additional latency.&lt;/p&gt;</comment>
                            <comment id="3867209" author="james.kovacs" created="Tue, 8 Jun 2021 19:35:33 +0000"  >&lt;p&gt;Hi, &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jochem%40netwinst.nl&quot; class=&quot;user-hover&quot; rel=&quot;jochem@netwinst.nl&quot;&gt;jochem@netwinst.nl&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thank you for opening &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-57518&quot; title=&quot;16% performance loss switching from Count to CountDocuments&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-57518&quot;&gt;SERVER-57518&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Regarding when &lt;tt&gt;Count&lt;/tt&gt; will be removed from the driver. We follow &lt;a href=&quot;https://semver.org/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Semantic Versioning&lt;/a&gt;, which means that we will only make API-breaking changes in major releases. Thus any deprecated methods won&apos;t be removed until the 3.0 release of the .NET/C# driver. (We are currently preparing for the 2.13.0 release.) Even when the .NET/C# driver removes the &lt;tt&gt;Count&lt;/tt&gt; method, you can still call it via the &lt;tt&gt;RunCommand&lt;/tt&gt; technique mentioned above until such time as the server removes support for it.&lt;/p&gt;

&lt;p&gt;I&apos;ll close this ticket and let you work with the Server team to discuss the performance regression in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-57518&quot; title=&quot;16% performance loss switching from Count to CountDocuments&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-57518&quot;&gt;SERVER-57518&lt;/a&gt;. Thank you for reporting this issue.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                            <comment id="3865496" author="JIRAUSER1260066" created="Tue, 8 Jun 2021 06:54:01 +0000"  >&lt;p&gt;Dear @JamesKovacs&lt;/p&gt;

&lt;p&gt;Thank you for your time and extensive support. I&apos;ve opened&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-57518&quot; title=&quot;16% performance loss switching from Count to CountDocuments&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-57518&quot;&gt;SERVER-57518&lt;/a&gt;. I hope they can help me&lt;br/&gt;
Will &quot;Count&quot; be removed from the driver in the future?&lt;/p&gt;

&lt;p&gt;Best regards,&lt;br/&gt;
Jochem&lt;/p&gt;</comment>
                            <comment id="3863494" author="james.kovacs" created="Mon, 7 Jun 2021 20:16:34 +0000"  >&lt;p&gt;Hi, &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jochem%40netwinst.nl&quot; class=&quot;user-hover&quot; rel=&quot;jochem@netwinst.nl&quot;&gt;jochem@netwinst.nl&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thank you for running the requested shell commands to confirm that the difference in execution time that you are seeing is due to server behaviour and not the driver. I recommend opening a SERVER ticket and referencing this one for context. You&apos;ll get better notifications and clearer communication as the original reporter of the issue if you open it yourself than if I do it on your behalf.&lt;/p&gt;

&lt;p&gt;Regarding your follow-on question about server support for &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; and &lt;tt&gt;CountDocuments&lt;/tt&gt;. When you call &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt;, the driver or shell sends the &lt;tt&gt;count&lt;/tt&gt; command without a predicate, which uses the collection metadata to estimate the number of documents in the collection. &lt;tt&gt;count&lt;/tt&gt; has been around since prior to MongoDB 1.0. When you call &lt;tt&gt;CountDocuments&lt;/tt&gt;, the driver or shell sends a &lt;tt&gt;$group/$sum&lt;/tt&gt; aggregation pipeline to MongoDB and the aggregation pipeline has been supported since MongoDB 2.2. (MongoDB 2.2 reached end-of-life in 2014.) Thus any currently supported version of MongoDB supports the commands underlying &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; and &lt;tt&gt;CountDocuments&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Please let us know if you have any additional questions or concerns.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                            <comment id="3859158" author="JIRAUSER1260066" created="Fri, 4 Jun 2021 06:53:03 +0000"  >&lt;p&gt;Dear @James Kovacs @james.kovacs ,&lt;/p&gt;

&lt;p&gt;Yes, this works. Thank you.&lt;/p&gt;

&lt;p&gt;The results of 20 iters are (which seem quite consistent)&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;db.Profiles.count({Om:0})) 450ms&lt;/li&gt;
	&lt;li&gt;db.Profiles.aggregate(&lt;a href=&quot;file://{$match: {Om:0}}, //{$group: {_id: null, count: {$sum:1}}}&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;\\{$match: {Om:0}}, \\{$group: {_id: null, count: {$sum:1}}}&lt;/a&gt;))&#160;575 ms&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;As you indicated this must mean it&apos;s a server thing.&lt;/p&gt;

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

&lt;p&gt;edit: thinking about this some more, simply stating that this is &quot;a server issue&quot; is maybe oversimplifying things.&lt;br/&gt;
I get the arguments for deprecating Count, but if there&apos;s no good alternative for all server versions, maybe it should not be done.&lt;/p&gt;</comment>
                            <comment id="3858094" author="james.kovacs" created="Thu, 3 Jun 2021 18:03:01 +0000"  >&lt;p&gt;Hi, Jochem,&lt;/p&gt;

&lt;p&gt;Thank you for trying to run those commands. The &lt;tt&gt;mongo&lt;/tt&gt; shell can be used to connect to a remote MongoDB cluster just as you would use Compass, MongoSH, or Robot3T. I wasn&apos;t suggesting that you log onto the &lt;tt&gt;mongod&lt;/tt&gt; server itself to run the &lt;tt&gt;mongo&lt;/tt&gt; shell. I know you&apos;ve got limited ability to access the cluster and cannot update its software.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;CountDocuments&lt;/tt&gt; isn&apos;t actually a MongoDB command but a helper method implemented by the drivers and shell. It appears that your version of Robo3T doesn&apos;t implement this helper. What is actually sent to the server is a &lt;tt&gt;$group/$sum&lt;/tt&gt; operation. The following is the &lt;tt&gt;$group/$sum&lt;/tt&gt; that would be generated so you can run the test in Robo3T:&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;function stopwatch(func) {&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;    var iters = 10;&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;    var start = new Date();&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;    for(var i=0; i&amp;lt;iters; i++) {&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;        func();&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;    }&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;    var end = new Date();&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;    print((end-start)/iters + &quot; ms&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;}&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;stopwatch(() =&amp;gt; db.largeCollection.count({Om:0}));&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;stopwatch(() =&amp;gt; db.largeCollection.aggregate([{$match: {Om:0}}, {$group: {_id: null, count: {$sum: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;We look forward to the results from this test.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                            <comment id="3856622" author="JIRAUSER1260066" created="Thu, 3 Jun 2021 06:46:22 +0000"  >&lt;p&gt;Dear @James Kovacs @james.kovacs ,&lt;/p&gt;

&lt;p&gt;Like I stated in earlier comments: I have no access to the Mongo server itself, as they are managed externally. I can only connect through things like MongoDB Compass and Robo 3T on a remote server&lt;/p&gt;

&lt;p&gt;Using MongoDB Compass 1.22.1 build in _MongoSH Beta&lt;br/&gt;
 When I run the &quot;stopwatch(() =&amp;gt;...)&quot; you suggest, I get a an error:&lt;br/&gt;
 &lt;b&gt;&lt;em&gt;MongoshInvalidInputError: Cannot pass a function that calls a Mongosh API method as an argument&lt;/em&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;I tried more, but thing like &quot;print(...)&quot; return undefined&lt;br/&gt;
 and &quot;new Date()&quot; returns {}&lt;/p&gt;

&lt;p&gt;When I try to run the commands through Robo 3T 1.2.1&lt;br/&gt;
 stopwatch(() =&amp;gt; db.Profiles.count({Om:0})); works: 448.7 ms&lt;br/&gt;
 stopwatch(() =&amp;gt; db.Profiles.countDocuments({Om:0})); fails:&lt;br/&gt;
 &lt;b&gt;&lt;em&gt;TypeError: db.Profiles.countDocuments is not a function&lt;/em&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;I will say in advance: I cannot update these versions of the software. These are also managed externally.&lt;/p&gt;</comment>
                            <comment id="3855396" author="james.kovacs" created="Wed, 2 Jun 2021 23:45:19 +0000"  >&lt;p&gt;Hi, Jochem,&lt;/p&gt;

&lt;p&gt;Thank you for expressing your concerns about the performance difference between &lt;tt&gt;Count(predicate)&lt;/tt&gt; and &lt;tt&gt;CountDocuments(predicate)&lt;/tt&gt;. We understand that a 34% performance degradation is significant and concerning.&lt;/p&gt;

&lt;p&gt;We appreciate you taking the time to explain your use case a bit more as it is clear now that &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; will not work for your situation. You need to supply a predicate, which will entail performing a &lt;tt&gt;count&lt;/tt&gt; operation (e.g. Count) or &lt;tt&gt;$group/$sum&lt;/tt&gt; aggregation (e.g. CountDocuments) on the server.&lt;/p&gt;

&lt;p&gt;Based on our repro, the performance difference between &lt;tt&gt;Count(predicate)&lt;/tt&gt; and &lt;tt&gt;CountDocuments(predicate)&lt;/tt&gt; is due to the query time on the server and not due to any additional time in the driver. We would like to confirm that this is also the case with your use case using your data set and indexes. To verify that the observed performance difference is due to query time on the server, please run the following commands in the &lt;tt&gt;mongo&lt;/tt&gt; shell (thus eliminating the .NET/C# driver as a contributing factor). Note that the &lt;tt&gt;stopwatch&lt;/tt&gt; helper function takes the average time of 10 runs. If the 10-run average doesn&apos;t report consistent timings, you can increase this to 100 to improve reproducibility.&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;function stopwatch(func) {&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;    var iters = 10;&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;    var start = new Date();&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;    for(var i=0; i&amp;lt;iters; i++) {&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;        func();&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;    }&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;    var end = new Date();&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;    print((end-start)/iters + &quot; ms&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;}&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;stopwatch(() =&amp;gt; db.largeCollection.count({Om:0}));&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;stopwatch(() =&amp;gt; db.largeCollection.countDocuments({Om:0}))&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;Please provide the output of these timings so that we can determine next steps. If the timings show that the performance difference is due to server query time, we can open a SERVER ticket to investigate further. If the timings show similar query performance for &lt;tt&gt;count&lt;/tt&gt; and &lt;tt&gt;countDocuments&lt;/tt&gt; on the server, then we can dig further into the .NET/C# driver - possibly comparing it to &lt;tt&gt;pymongo&lt;/tt&gt; or another driver - to understand the performance differences between &lt;tt&gt;Count&lt;/tt&gt; and &lt;tt&gt;CountDocuments&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;We appreciate your time and patience as we continue to investigate this issue together.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                            <comment id="3853096" author="JIRAUSER1260066" created="Wed, 2 Jun 2021 07:18:04 +0000"  >&lt;p&gt;Dear @James Kovacs @james.kovacs ,&lt;/p&gt;

&lt;p&gt; &amp;gt; &lt;em&gt;To solve these problems, we split&#160;&lt;tt&gt;count&lt;/tt&gt;&#160;into two distinct operations:&#160;&lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt;&#160;and&#160;&lt;tt&gt;CountDocuments&lt;/tt&gt;...&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Yes, I understand.  This has been stated a number of times by different people, but it doesn&apos;t seem to be as simple as that. The underlying function has changed (seen in the performance difference), as well as the interface (See remarks: &lt;a href=&quot;https://mongodb.github.io/mongo-csharp-driver/2.8/apidocs/html/M_MongoDB_Driver_IMongoCollection_1_CountDocuments.htm&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://mongodb.github.io/mongo-csharp-driver/2.8/apidocs/html/M_MongoDB_Driver_IMongoCollection_1_CountDocuments.htm&lt;/a&gt;). Thus, it&apos;s no drop-in replacement.&lt;/p&gt;

&lt;p&gt; &amp;gt; &lt;em&gt;Hopefully that explanation helps you understand why&#160;&lt;tt&gt;CountDocuments&lt;/tt&gt;&#160;can be much slower than&#160;&lt;tt&gt;count&lt;/tt&gt;&#160;especially for large collections.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well, no, especially when combined with&lt;/p&gt;

&lt;p&gt; &amp;gt; &lt;em&gt;Note that the&#160;&lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt;&#160;and&#160;&lt;tt&gt;CountDocuments&lt;/tt&gt;&#160;methods in the .NET/C# driver are very thin wrappers around the underlying metadata count and&#160;&lt;tt&gt;$group&lt;/tt&gt;/&lt;tt&gt;$sum&lt;/tt&gt;&#160;operations executed on the server.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Becasue in the code I got from Mikalai, it shows that &lt;/p&gt;

&lt;p&gt;database.RunCommand&amp;lt;BsonDocument&amp;gt;(new BsonDocument(&quot;count&quot;, &amp;lt;Collection name&amp;gt;).Add(&quot;query&quot;, filter));&lt;/p&gt;

&lt;p&gt;is about as fast as Count(), while CountDocuments() is 34% slower. That would seem more is happening in CountDocuments which slows down the evaluation.&lt;/p&gt;

&lt;p&gt; &amp;gt; &lt;em&gt;Hopefully this information assists you in tuning your count operations.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;No, I don&apos;t know how to properly solve this. Losing ~150ms in a query is significant in an applications with many transactions. And we have a predicate, so neither EstimatedDocumentCount not CountDocuments seems to be a &quot;good&quot; option,&lt;br/&gt;
My first instinct is just to keep using Count(). And if it is removed from the driver in the future, to use Mikalai&apos;s raw command. &lt;br/&gt;
However, I don&apos;t know how to solve this for the IFindFluent interface....&lt;/p&gt;

&lt;p&gt;To me, it is bizarre that a performance loss of 34% is considered an acceptable solution for any application, even considering the problems with the previous version. How can you sell this to customers? I mean, our customers expect a performance &amp;gt;improvement&amp;lt; with every new version. If we would release with a 34% performance degradation, our customer support line would be overloaded with complaints.&lt;/p&gt;</comment>
                            <comment id="3850113" author="james.kovacs" created="Mon, 31 May 2021 20:47:46 +0000"  >&lt;p&gt;Hi, Jochem,&lt;/p&gt;

&lt;p&gt;Thank you for your patience in explaining the problem that you&apos;ve encountered and providing the requested data on documents counts and results. I would like to take a step back to discuss why &lt;tt&gt;count&lt;/tt&gt; was deprecated in the first place as it will provide context as well as a path forward.&lt;/p&gt;

&lt;p&gt;The problem with &lt;tt&gt;count&lt;/tt&gt; is that it has historically done two very different things with very different performance profiles. &lt;tt&gt;count&lt;/tt&gt; without a predicate would query the collection metadata, which is a very fast operation. &lt;tt&gt;count&lt;/tt&gt; with a predicate has to query the collection&apos;s documents, hopefully supported by an index, to determine the document count. This could be a very time-consuming, I/O intensive operation that might require a full collection scan if a supporting index isn&apos;t available. Another problem is sharded collections where &lt;tt&gt;count&lt;/tt&gt; without a predicate will simply sum up the metadata counts on each shard - which could over-count documents if there were orphaned documents or in-flight migrations.&lt;/p&gt;

&lt;p&gt;To solve these problems, we split &lt;tt&gt;count&lt;/tt&gt; into two distinct operations: &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; and &lt;tt&gt;CountDocuments&lt;/tt&gt;...&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; simply returns the document count from the collection metadata. This is why you cannot supply a predicate to &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; - because it is simply returning the value in the collection metadata. It is guaranteed to be fast because it never has to touch documents or indexes. The downside is that it is estimated and can over-count documents in sharded collections due to orphans or migrations.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;CountDocuments&lt;/tt&gt; is implemented using the Aggregation pipeline, specifically &lt;tt&gt;$group&lt;/tt&gt;/&lt;tt&gt;$sum&lt;/tt&gt;. It will give an accurate count of documents in a collection based on a predicate. Even if no predicate is supplied, it will execute the &lt;tt&gt;$group&lt;/tt&gt;/&lt;tt&gt;$sum&lt;/tt&gt; aggregation with an empty filter to obtain the true count of documents in the collection correctly filtering out orphans in sharded collections. While it provides a more accurate count, it does require more work by the server to return the result.&lt;/p&gt;

&lt;p&gt;If you only need an approximate count of documents in a collection, then &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; is the method you should use. It is going to be much faster because it is only examining collection metadata but be aware that it can over-count orphans. If you need an accurate document count, then &lt;tt&gt;CountDocuments&lt;/tt&gt; is the method you should use and you should ensure that you have an appropriate index present to support the supplied predicate.&lt;/p&gt;

&lt;p&gt;Hopefully that explanation helps you understand why &lt;tt&gt;CountDocuments&lt;/tt&gt; can be much slower than &lt;tt&gt;count&lt;/tt&gt; especially for large collections. When migrating away from the deprecated &lt;tt&gt;count&lt;/tt&gt; operation, the question really becomes how accurate do you require your counts? Can you code tolerate over-counting orphans? If so, then &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; will likely be sufficient for your needs. If you need to supply a predicate or cannot tolerate over-counting orphans, then you should use &lt;tt&gt;CountDocuments&lt;/tt&gt; and ensure that you have an index to support your predicate.&lt;/p&gt;

&lt;p&gt;In summary &lt;tt&gt;count&lt;/tt&gt; has been split into two operations: &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; and &lt;tt&gt;CountDocuments&lt;/tt&gt;. Rather than implicitly switching between reading from metadata and actually counting the documents (using an index or full collection scan) as we did with &lt;tt&gt;count&lt;/tt&gt;, implementers can now chose to read the count from metadata via &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; or accurately counting the documents in the collection using &lt;tt&gt;CountDocuments&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Note that the &lt;tt&gt;EstimatedDocumentCount&lt;/tt&gt; and &lt;tt&gt;CountDocuments&lt;/tt&gt; methods in the .NET/C# driver are very thin wrappers around the underlying metadata count and &lt;tt&gt;$group&lt;/tt&gt;/&lt;tt&gt;$sum&lt;/tt&gt; operations executed on the server. Thus the majority of the performance difference will be due to server execution and not the .NET/C# implementation in the driver. Hopefully this information assists you in tuning your count operations.&lt;/p&gt;

&lt;p&gt;Please let us know if you have any additional questions.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                            <comment id="3845725" author="JIRAUSER1260066" created="Thu, 27 May 2021 18:36:44 +0000"  >&lt;p&gt;@Mikalai Mazurenka / @mikalai.mazurenka,&lt;/p&gt;

&lt;p&gt;I modified your code to run the original query on mt production database (I guess it does the same, didn&apos;t report the result count)&lt;/p&gt;

&lt;p&gt;The numbers I see are:&lt;/p&gt;

&lt;p&gt;Average results from 300 runs&#160;&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Count 426&lt;/li&gt;
	&lt;li&gt;CountDocuments 571&lt;/li&gt;
	&lt;li&gt;RunCommand 429&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;So CountDocuments is taking 34% more time! I consider that quite significant. And thus a big problem&lt;/p&gt;

&lt;p&gt;i.e. CountDocuments is &lt;b&gt;not&lt;/b&gt; a drop-in replacement for Count...&lt;/p&gt;</comment>
                            <comment id="3843735" author="JIRAUSER1260066" created="Thu, 27 May 2021 07:21:01 +0000"  >&lt;p&gt;@Mikalai Mazurenka / @mikalai.mazurenka,&lt;/p&gt;

&lt;p&gt;I&apos;ve modified your test to match our corporate password protected server.&lt;/p&gt;

&lt;p&gt;Results&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Count 424&lt;/li&gt;
	&lt;li&gt;CountDocuments 499&lt;/li&gt;
	&lt;li&gt;RunCommand 425&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;That&apos;s all good and well, but doesn&apos;t represent my results. I will update your search to match our database documents and a realistic search.&lt;/p&gt;

&lt;p&gt;The DB is 3.4.9&lt;/p&gt;

&lt;p&gt;The Driver is 2.10.3&lt;/p&gt;

&lt;p&gt;What do you mean with &quot;Configuration&quot;?&lt;/p&gt;

&lt;p&gt;(Note: server is corporate and app is also very big and maintained by a number of people, so &quot;update your version&quot; is not achievable by me)&lt;/p&gt;</comment>
                            <comment id="3843705" author="JIRAUSER1260066" created="Thu, 27 May 2021 06:34:26 +0000"  >&lt;p&gt;@Jeffrey Yemin / @jeff.yemin,&lt;/p&gt;

&lt;p&gt;The numbers are in the earlier comments. Total documents&#160;2&apos;721&apos;199, query returns&#160;2&apos;060&apos;277.&lt;/p&gt;</comment>
                            <comment id="3839464" author="mikalai.mazurenka" created="Tue, 25 May 2021 19:18:43 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jochem%40netwinst.nl&quot; class=&quot;user-hover&quot; rel=&quot;jochem@netwinst.nl&quot;&gt;jochem@netwinst.nl&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Could you please use the provided example to check your execution results: &lt;a href=&quot;https://gist.github.com/MikalaiMazurenka/10c7c092c4773ae10ea76f67f53f5fb0&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/MikalaiMazurenka/10c7c092c4773ae10ea76f67f53f5fb0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note, that for cleaner results I added a time period for driver to set up and calculate average from multiple runs on large dataset, also have the &lt;tt&gt;RunCommand&lt;/tt&gt; present as a &quot;control group&quot;.&lt;/p&gt;

&lt;p&gt;I see around 5% difference, but that may depend on server version, configuration and less on secondary parameters like OS, compression, encryption, authentication, etc.&lt;/p&gt;

&lt;p&gt;So could you please provide your results along with server version, driver version and configuration?&lt;/p&gt;</comment>
                            <comment id="3837329" author="jeff.yemin" created="Tue, 25 May 2021 14:00:17 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jochem%40netwinst.nl&quot; class=&quot;user-hover&quot; rel=&quot;jochem@netwinst.nl&quot;&gt;jochem@netwinst.nl&lt;/a&gt; sorry, one more question.  What does count actually return (i.e. how many documents match the query filter)?&lt;/p&gt;</comment>
                            <comment id="3834809" author="JIRAUSER1260066" created="Tue, 25 May 2021 07:00:43 +0000"  >&lt;p&gt;Hi @Jeff Yemin and @Mikalai Mazurenka .... @jeff.yemin and @mikalai.mazurenka , (&amp;lt;- I don;t get how user tagging works...)&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Total number of documents: (For my example: differs between collections and customers) 2&apos;721&apos;199 documents&lt;/li&gt;
	&lt;li&gt;Query filter: Filter.Eq(&quot;Om&quot;, 0)&lt;/li&gt;
	&lt;li&gt;All of the indexes on this collection: { &quot;Pr.P2&quot; : 1, &quot;CD&quot; : 1 } { &quot;Pr.P2&quot; : 1 } { &quot;Pr.P7&quot; : 1 } { &quot;HI.B&quot; : 1 } { &quot;HI.C&quot; : 1 } { &quot;PI.RI&quot; : 1 } { &quot;Om&quot; : 1 } { &quot;Pr.P100&quot; : 1 } { &quot;Pr.P84&quot; : 1 } { &quot;Pr.P2&quot; : 1, &quot;Pr.P8&quot; : 1 } { &quot;PI.I&quot; : 1 }&lt;/li&gt;
	&lt;li&gt;Deployement: it&apos;s a single server. So no scaling. (I think it defaults to sharding?)&lt;/li&gt;
&lt;/ul&gt;
</comment>
                            <comment id="3816509" author="jeff.yemin" created="Sun, 23 May 2021 14:28:45 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jochem%40netwinst.nl&quot; class=&quot;user-hover&quot; rel=&quot;jochem@netwinst.nl&quot;&gt;jochem@netwinst.nl&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Can you let us know:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;total number of documents in collection&lt;/li&gt;
	&lt;li&gt;the query filter you&apos;re using&lt;/li&gt;
	&lt;li&gt;all the indexes on the collection&lt;/li&gt;
	&lt;li&gt;deployment (replica set or sharded)&lt;/li&gt;
&lt;/ul&gt;
</comment>
                            <comment id="3816381" author="JIRAUSER1260066" created="Sun, 23 May 2021 11:08:34 +0000"  >&lt;p&gt;Did more tests, based on &lt;a href=&quot;https://stackoverflow.com/q/67657917&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;this Stack Overflow item&lt;/a&gt;. Added a filter and got differen results:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Count returns 2060277 and took ~434 ms.&lt;/li&gt;
	&lt;li&gt;CountDocuments returns 2060277 and took ~575 ms.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Although &lt;em&gt;much&lt;/em&gt; better, it&apos;s still &amp;gt;25% slower. That&apos;s significant and we would rather avoid that, as perfomance is already an issue. How can I achieve that?&lt;/p&gt;</comment>
                            <comment id="3815940" author="JIRAUSER1260066" created="Sun, 23 May 2021 08:55:09 +0000"  >&lt;p&gt;I did some tests myself and found the following for a small collection,which already shows the differences:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Count returns 6600 and took 12 ms.&lt;/li&gt;
	&lt;li&gt;CountDocuments returns 6600 and took 25 ms.&lt;/li&gt;
	&lt;li&gt;EstimatedDocumentCount returns 6600 and took 2 ms.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;But then for a big collection:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Count returns 2721199 and took 12 ms.&lt;/li&gt;
	&lt;li&gt;CountDocuments returns 2721199 and took 196406 ms.&lt;/li&gt;
	&lt;li&gt;EstimatedDocumentCount returns 2721199 and took 4 ms.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;That&apos;s 196 seconds! &lt;b&gt;16367x&lt;/b&gt; slower! &lt;em&gt;Totally&lt;/em&gt; unacceptable...&lt;/p&gt;

&lt;p&gt;What are we supposed to do this way?&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="3795416" author="kaitlin.mahar" created="Thu, 20 May 2021 16:23:42 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jochem%40netwinst.nl&quot; class=&quot;user-hover&quot; rel=&quot;jochem@netwinst.nl&quot;&gt;jochem@netwinst.nl&lt;/a&gt;, Thank you for reaching out. I have moved your ticket to the CSHARP project for their team to triage, as this appears to be a question about the C# driver rather than the Node.js driver.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10520">
                    <name>Problem/Incident</name>
                                                                <inwardlinks description="is caused by">
                                        <issuelink>
            <issuekey id="1772324">SERVER-57518</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="590831">NODE-1638</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <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|hyz08v:</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>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>