<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:31 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-335] MongoCollection.Count() method does not respect SlaveOk</title>
                <link>https://jira.mongodb.org/browse/CSHARP-335</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;&lt;b&gt;mongoDB Setup&lt;/b&gt;&lt;br/&gt;
Replica Set with all secondaries, no primary is up.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Sample Code:&lt;/b&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;var server = MongoServer.Create(ConfigurationManager.AppSettings&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;connectionString&amp;quot;&amp;#93;&lt;/span&gt;);&lt;br/&gt;
var db = server.GetDatabase(&quot;myDb&quot;, SafeMode.False);&lt;/p&gt;

&lt;p&gt;var settings = db.CreateCollectionSettings&amp;lt;Task&amp;gt;(&quot;Tasks&quot;);&lt;br/&gt;
settings.SlaveOk = true;&lt;br/&gt;
settings.SafeMode = SafeMode.False;&lt;/p&gt;

&lt;p&gt;var taskCollection = db.GetCollection(settings);&lt;/p&gt;

&lt;p&gt;var tasks = taskCollection.FindAll();&lt;/p&gt;

&lt;p&gt;var taskCount = taskCollection.Count();&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I can get the collection of items fine from taskCollection.FindAll(), but if I call taskCollection.Count(), driver throws the following error:&lt;/p&gt;

&lt;p&gt;MongoDB.Driver.MongoConnectionException: Unable to connect to the primary member of the replica set: No connection could be made because the target machine actively refused it&lt;/p&gt;

&lt;p&gt;Some troubleshooting leads me to believe the MongoCollection.Count() implementation is not respecting the SlaveOk setting.&lt;/p&gt;</description>
                <environment></environment>
        <key id="23284">CSHARP-335</key>
            <summary>MongoCollection.Count() method does not respect SlaveOk</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="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="alanl">Alan L.</reporter>
                        <labels>
                            <label>replication</label>
                    </labels>
                <created>Wed, 5 Oct 2011 22:35:51 +0000</created>
                <updated>Thu, 2 Apr 2015 18:28:06 +0000</updated>
                            <resolved>Thu, 6 Oct 2011 21:20:47 +0000</resolved>
                                    <version>1.2</version>
                                    <fixVersion>1.3</fixVersion>
                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="58947" author="rstam" created="Thu, 6 Oct 2011 21:20:47 +0000"  >&lt;p&gt;See &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-336&quot; title=&quot;Add support for sending commands to secondaries when slaveOk is true&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-336&quot;&gt;&lt;del&gt;CSHARP-336&lt;/del&gt;&lt;/a&gt; instead.&lt;/p&gt;</comment>
                            <comment id="58946" author="rstam" created="Thu, 6 Oct 2011 21:20:27 +0000"  >&lt;p&gt;I&apos;m opening a new issue (&lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-336&quot; title=&quot;Add support for sending commands to secondaries when slaveOk is true&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-336&quot;&gt;&lt;del&gt;CSHARP-336&lt;/del&gt;&lt;/a&gt;) which addresses commands in general, not just the Count command.&lt;/p&gt;</comment>
                            <comment id="58757" author="rstam" created="Thu, 6 Oct 2011 03:50:56 +0000"  >&lt;p&gt;You are correct. Count is actually executed as a command, and all commands are sent to the primary.&lt;/p&gt;

&lt;p&gt;Many commands only work on the primary. While count theoretically could be sent to a secondary, the driver doesn&apos;t know (at least not yet) on a command by command case whether that particular command could be sent to the secondary.&lt;/p&gt;

&lt;p&gt;You could work around this by working at a lower level and sending the equivalent query to the $cmd collection using FindOne, in which case slaveOk would be honored. Let me know if you are interested in doing that and need help writing it that way.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="23329">CSHARP-336</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </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|hrh8br:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14148</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>