<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 05:18:55 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-49098] countDocuments() set query to {} if it&apos;s empty</title>
                <link>https://jira.mongodb.org/browse/SERVER-49098</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;&#160;&lt;/p&gt;

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

&lt;p&gt;The shell does not set the query to {} for countDocuments() if it&apos;s empty.&lt;/p&gt;

&lt;p&gt;i.e. the following returns an error from ADL as it is converted to a $match with no document passed in.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&amp;gt; db.data.countDocuments()&lt;/tt&gt;&lt;/p&gt;

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

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

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

&lt;p&gt;countDocuments() doesn&#8217;t seem to work with federated queries:&lt;tt&gt;&amp;gt; db.data.count()&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;10000&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;&amp;gt; db.data.countDocuments()&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;2020-06-25T00:12:36.334+0200 E QUERY &lt;span class=&quot;error&quot;&gt;&amp;#91;js&amp;#93;&lt;/span&gt; uncaught exception: Error: command failed: {&lt;/tt&gt;&lt;br/&gt;
 {{ &quot;ok&quot; : 0,}}&lt;br/&gt;
 {{ &quot;errmsg&quot; : &quot;failed parsing stage: $match stage must have a document as its only argument, correlationID = 161b9a7d52a6363a253a8c3e&quot;,}}&lt;br/&gt;
 {{ &quot;code&quot; : 9,}}&lt;br/&gt;
 {{ &quot;codeName&quot; : &quot;FailedToParse&quot;}}&lt;br/&gt;
 &lt;tt&gt;} : aggregate failed :&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;_getErrorWithCode@src/mongo/shell/utils.js:25:13&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;doassert@src/mongo/shell/assert.js:18:14&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;_assertCommandWorked@src/mongo/shell/assert.js:583:17&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;assert.commandWorked@src/mongo/shell/assert.js:673:16&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;DB.prototype._runAggregate@src/mongo/shell/db.js:266:5&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1012:12&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;DBCollection.prototype.countDocuments@src/mongo/shell/collection.js:1423:17&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;@(shell):1:1&lt;/tt&gt;&lt;br/&gt;
 &#160;&lt;br/&gt;
 18 replies&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593037544227100?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;what happens when you run aggregate command and&#160;{&lt;tt&gt;$count:&apos;c&apos;&lt;/tt&gt;}&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-UNX1Z65JL-3043f6c84b91-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/UNX1Z65JL&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Danilo Nobrega&lt;/a&gt;&#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593038047227500?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;gt; db.data.aggregate({$count:&#8216;c&#8217;})&lt;/p&gt;

{ &#8220;c&#8221; : 10000 }

&lt;p&gt;&#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-UNX1Z65JL-3043f6c84b91-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/UNX1Z65JL&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Danilo Nobrega&lt;/a&gt;&#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593038076227700?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;it works&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593040022227900?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;that&apos;s all that the shell helper does for&#160;&lt;tt&gt;countDocuments&lt;/tt&gt;&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593040047228100?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;can you type&#160;&lt;tt&gt;db.data.countDocuments&lt;/tt&gt;&#160; without the&#160;&lt;tt&gt;()&lt;/tt&gt;&#160;and paste what you see?&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593040067228300?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;oh&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593040080228500?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I bet I know - you need to run it as&#160;&lt;tt&gt;db.data.countDocuments({})&lt;/tt&gt;&#160;I bet.&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593040109228700?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;bug in the shell&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593040131228900?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;query should be `query = query || {} ` same as options.&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593040196229100?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;it&apos;s a bug in the&#160;&lt;tt&gt;shell&lt;/tt&gt;&#160;component.&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593040204229300?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;need to file a Jira ticket on it.&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593040217229500?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;8 hours ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;surprised if there isn&apos;t one already though but then why didn&apos;t we fix it?&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-UNX1Z65JL-3043f6c84b91-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/UNX1Z65JL&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Danilo Nobrega&lt;/a&gt;&#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593066742238600?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;22 minutes ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;gt; db.data.countDocuments&lt;br/&gt;
 function(query, options)&lt;/p&gt;

&lt;p&gt;{ &#160;&#160;&#160;&#160;&#8220;use strict&#8221;; &#160;&#160;&#160;&#160;let pipeline = [&lt;/p&gt;

{&#8220;$match&#8221;: query}

&lt;p&gt;];&lt;br/&gt;
 &#160;&#160;&#160;&#160;options = options || {};&lt;br/&gt;
 &#160;&#160;&#160;&#160;assert.eq(typeof options, &#8220;object&#8221;, &#8220;&#8216;options&#8217; argument must be an object&#8221;);&#160;&#160;&#160;&#160;if (options.skip)&lt;/p&gt;

&lt;p&gt;{ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pipeline.push(&lt;/p&gt;

{&#8220;$skip&#8221;: options.skip}

&lt;p&gt;);&lt;br/&gt;
 &#160;&#160;&#160;&#160;}&lt;br/&gt;
 &#160;&#160;&#160;&#160;if (options.limit)&lt;/p&gt;

&lt;p&gt;{ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pipeline.push(&lt;/p&gt;

{&#8220;$limit&#8221;: options.limit}

&lt;p&gt;);&lt;br/&gt;
 &#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;// Construct an aggregation pipeline stage with sum to calculate the number of all documents.&lt;br/&gt;
 &#160;&#160;&#160;&#160;pipeline.push({&#8220;$group&#8221;: {&#8220;_id&#8221;: null, &#8220;n&#8221;:&lt;/p&gt;

{&#8220;$sum&#8221;: 1}

&lt;p&gt;}});&#160;&#160;&#160;&#160;// countDocument options other than filter, skip, and limit, are added to the aggregate command.&lt;br/&gt;
 &#160;&#160;&#160;&#160;let aggregateOptions = {};&#160;&#160;&#160;&#160;if (options.hint)&lt;/p&gt;

{ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;aggregateOptions.hint = options.hint; &#160;&#160;&#160;&#160;}

&lt;p&gt;&#160;&#160;&#160;&#160;if (options.maxTimeMS)&lt;/p&gt;

{ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;aggregateOptions.maxTimeMS = options.maxTimeMS; &#160;&#160;&#160;&#160;}

&lt;p&gt;&#160;&#160;&#160;&#160;if (options.collation)&lt;/p&gt;

{ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;aggregateOptions.collation = options.collation; &#160;&#160;&#160;&#160;}

&lt;p&gt;&#160;&#160;&#160;&#160;// Format cursor into an array.&lt;br/&gt;
 &#160;&#160;&#160;&#160;const res = this.aggregate(pipeline, aggregateOptions).toArray();&lt;br/&gt;
 &#160;&#160;&#160;&#160;if (res.length)&lt;/p&gt;

{ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return res[0].n; &#160;&#160;&#160;&#160;}

&lt;p&gt;&#160;&#160;&#160;&#160;return 0;&lt;br/&gt;
 }&lt;br/&gt;
 &amp;gt;&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-U0V2TBWTT-dcc7e089716b-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/U0V2TBWTT&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;asya&lt;/a&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://slack-imgs.com/?c=1&amp;amp;o1=gu&amp;amp;url=https%3A%2F%2Fa.slack-edge.com%2Fproduction-standard-emoji-assets%2F10.2%2Fapple-small%2F1f4ac%402x.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt; &#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593066790239300?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;21 minutes ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yeah it&#8217;s missing a line. Should set query to {} if it&#8217;s empty.&lt;br/&gt;
 &#160;&lt;br/&gt;
 &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://ca.slack-edge.com/T024FNNHU-UNX1Z65JL-3043f6c84b91-48&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;br/&gt;
 &lt;a href=&quot;https://app.slack.com/team/UNX1Z65JL&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Danilo Nobrega&lt;/a&gt;&#160;&#160;&lt;a href=&quot;https://mongodb.slack.com/archives/C1QM2S60K/p1593066805239500?thread_ts=1593036938.227000&amp;amp;cid=C1QM2S60K&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;21 minutes ago&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;gt; db.data.countDocuments({})&lt;br/&gt;
 10000&lt;br/&gt;
 &amp;gt;&lt;/p&gt;</description>
                <environment></environment>
        <key id="1389847">SERVER-49098</key>
            <summary>countDocuments() set query to {} if it&apos;s empty</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="13202">Works as Designed</resolution>
                                        <assignee username="jonathan.streets@mongodb.com">Jonathan Streets</assignee>
                                    <reporter username="danilo.nobrega@mongodb.com">Danilo Nobrega</reporter>
                        <labels>
                    </labels>
                <created>Thu, 25 Jun 2020 06:55:42 +0000</created>
                <updated>Fri, 27 Oct 2023 13:52:48 +0000</updated>
                            <resolved>Mon, 12 Oct 2020 14:36:23 +0000</resolved>
                                                                    <component>Shell</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="3441904" author="danilo.nobrega" created="Tue, 13 Oct 2020 12:25:56 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jonathan.streets&quot; class=&quot;user-hover&quot; rel=&quot;jonathan.streets&quot;&gt;jonathan.streets&lt;/a&gt;&#160;alright. I thought I would flag it as a bug, but if it is clear in the documentation, I guess that&apos;s acceptable.&lt;/p&gt;</comment>
                            <comment id="3439390" author="jonathan.streets" created="Mon, 12 Oct 2020 14:36:10 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=danilo.nobrega&quot; class=&quot;user-hover&quot; rel=&quot;danilo.nobrega&quot;&gt;danilo.nobrega&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We haven&#8217;t heard back from you for some time, so I&#8217;m going to mark this ticket as resolved. If this is still an issue for you, please provide additional information and we will reopen the ticket.&lt;/p&gt;

&lt;p&gt;Regards,&lt;/p&gt;

&lt;p&gt;Jon&lt;/p&gt;</comment>
                            <comment id="3283360" author="jonathan.streets" created="Mon, 13 Jul 2020 20:26:55 +0000"  >&lt;p&gt;&lt;b&gt;Issue:&lt;/b&gt; db.collection.countDocuments() with no arguments returns an error. The documentation for &lt;a href=&quot;https://docs.mongodb.com/manual/reference/method/db.collection.countDocuments/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;countDocuments()&lt;/a&gt;&#160;states in the examples section, to get a count of documents one can use &lt;tt&gt;db.orders.countDocuments({})&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;e.g.&lt;/em&gt;&#160;The following mongo shell commands complete successfully:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;db.feed.countDocuments({})&lt;/li&gt;
	&lt;li&gt;db.feed.count()&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The following command&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;db.feed.countDocuments()&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;returns an error&#160;&lt;/p&gt;

{ &quot;ok&quot; : 0, &quot;errmsg&quot; : &quot;the match filter must be an expression in an object&quot;, &quot;code&quot; : 15959, &quot;codeName&quot; : &quot;Location15959&quot; }

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

&lt;p&gt;&#160;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=danilo.nobrega&quot; class=&quot;user-hover&quot; rel=&quot;danilo.nobrega&quot;&gt;danilo.nobrega&lt;/a&gt;, i think this is how the command is meant to work ?&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>3.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Mon, 13 Jul 2020 20:26:55 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        3 years, 17 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>
                            3 years, 17 weeks, 1 day ago
                        </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>danilo.nobrega@mongodb.com</customfieldvalue>
            <customfieldvalue>jonathan.streets@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hxri07:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hxeh93:</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|hxr49j:</customfieldvalue>

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