<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:55:26 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>[JAVA-1767] listCollections helper fails with direct connection to a secondary</title>
                <link>https://jira.mongodb.org/browse/JAVA-1767</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;According the the &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#use-of-read-preferences-with-commands&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;server selection specification&lt;/a&gt;, when directly connected to a single MongoDB server command helpers like listCollections that intentionally ignore the default read preference on MongoDatabase should still send the command to the server, even if it&apos;s a non-primary member of a replica set. &lt;/p&gt;

&lt;p&gt;Currently the driver fails to execute listCollections and other similar command when directly connected to a non-primary replica set member.&lt;/p&gt;

&lt;p&gt;===============================================&lt;br/&gt;
Original Description:&lt;/p&gt;

&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;I am not able to get to connect to the secondary using secondaryPreferred global preference. Here is my code&lt;/p&gt;

&lt;p&gt;            MongoClientOptions options = new MongoClientOptions.Builder().connectTimeout(20000).readPreference(ReadPreference.secondaryPreferred()).serverSelectionTimeout(12000).build();&lt;br/&gt;
....&lt;br/&gt;
            m = new MongoClient(new ServerAddress(host, port), creds, options);&lt;/p&gt;

&lt;p&gt;When the provided host is a secondary of a replica set the code fails with the following error&lt;br/&gt;
 Timed out after 12000 ms while waiting for a server that matches ReadPreferenceServerSelector&lt;/p&gt;
{readPreference=primary}
&lt;p&gt;.&lt;br/&gt;
 Client view of cluster state is {type=REPLICA_SET, servers=[&lt;/p&gt;
{address=sg-302test6-1063.devservers.mongodirector.com:27017, type=REPLICA_SET_SECONDARY, roundTripTime=2.8 ms, state=C
ONNECTED}
&lt;p&gt;]&lt;/p&gt;

&lt;p&gt;Looks like the right readPreference is not being preserved in this case.&lt;/p&gt;

&lt;p&gt;If I try to connect to the primary it appears to work fine.&lt;/p&gt;</description>
                <environment></environment>
        <key id="198458">JAVA-1767</key>
            <summary>listCollections helper fails with direct connection to a secondary</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="jeff.yemin@mongodb.com">Jeffrey Yemin</assignee>
                                    <reporter username="dharshanr@scalegrid.net">Dharshan Rangegowda</reporter>
                        <labels>
                            <label>regression</label>
                    </labels>
                <created>Fri, 17 Apr 2015 02:26:11 +0000</created>
                <updated>Fri, 1 Apr 2016 21:06:55 +0000</updated>
                            <resolved>Mon, 20 Apr 2015 18:43:43 +0000</resolved>
                                    <version>3.0.0</version>
                                    <fixVersion>3.0.1</fixVersion>
                                    <component>Cluster Management</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="905767" author="jeff.yemin" created="Tue, 5 May 2015 19:38:44 +0000"  >&lt;p&gt;Closed for 3.0.1 release.&lt;/p&gt;</comment>
                            <comment id="901969" author="jeff.yemin" created="Thu, 30 Apr 2015 13:01:22 +0000"  >&lt;p&gt;Sorry about that.  This is the proper link: &lt;a href=&quot;https://oss.sonatype.org/content/repositories/snapshots/org/mongodb/mongo-java-driver/3.1.0-SNAPSHOT/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://oss.sonatype.org/content/repositories/snapshots/org/mongodb/mongo-java-driver/3.1.0-SNAPSHOT/&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="901703" author="dharshanr@scalegrid.net" created="Thu, 30 Apr 2015 02:43:16 +0000"  >&lt;p&gt;I hit another similar issue which I have filed - &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-1786&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/JAVA-1786&lt;/a&gt;. &lt;/p&gt;</comment>
                            <comment id="901691" author="dharshanr@scalegrid.net" created="Thu, 30 Apr 2015 02:06:07 +0000"  >&lt;p&gt;Thanks. I get a 404 when I try to download the snapshot release&lt;/p&gt;

&lt;p&gt;404 - Path /org/mongodb/mongo-java-driver/3.1.0-SNAPSHOT/ not found in local storage of repository &quot;Releases&quot; &lt;span class=&quot;error&quot;&gt;&amp;#91;id=releases&amp;#93;&lt;/span&gt;&lt;/p&gt;</comment>
                            <comment id="901223" author="jeff.yemin" created="Wed, 29 Apr 2015 18:07:42 +0000"  >&lt;p&gt;Hi Darshan,&lt;/p&gt;

&lt;p&gt;We don&apos;t have a release date yet, but I expect it will be in the next couple of weeks.  Until then you can use the snapshot release.  See &lt;a href=&quot;http://mongodb.github.io/mongo-java-driver/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://mongodb.github.io/mongo-java-driver/&lt;/a&gt; for instructions on how to do that.&lt;/p&gt;

&lt;p&gt;Thanks for your patience.&lt;/p&gt;</comment>
                            <comment id="901187" author="dharshanr@scalegrid.net" created="Wed, 29 Apr 2015 17:58:29 +0000"  >&lt;p&gt;Hi Jeff - when will 3.0.1 be available at &lt;a href=&quot;https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongo-java-driver/?&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongo-java-driver/?&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="893093" author="xgen-internal-githook" created="Mon, 20 Apr 2015 18:28:38 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;jyemin&apos;, u&apos;name&apos;: u&apos;Jeff Yemin&apos;, u&apos;email&apos;: u&apos;jeff.yemin@10gen.com&apos;}
&lt;p&gt;Message: When selecting a server that satisifies a read preference, select any ok server when cluster connection mode is SINGLE.&lt;/p&gt;

&lt;p&gt; &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-1767&quot; title=&quot;listCollections helper fails with direct connection to a secondary&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-1767&quot;&gt;&lt;del&gt;JAVA-1767&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: 3.0.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/b1ec0944ce8df1247876ad2f05da643053fb8bee&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/b1ec0944ce8df1247876ad2f05da643053fb8bee&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="892942" author="xgen-internal-githook" created="Mon, 20 Apr 2015 16:49:07 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;jyemin&apos;, u&apos;name&apos;: u&apos;Jeff Yemin&apos;, u&apos;email&apos;: u&apos;jeff.yemin@10gen.com&apos;}
&lt;p&gt;Message: When selecting a server that satisifies a read preference, select any ok server when cluster connection mode is SINGLE.&lt;/p&gt;

&lt;p&gt; &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-1767&quot; title=&quot;listCollections helper fails with direct connection to a secondary&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-1767&quot;&gt;&lt;del&gt;JAVA-1767&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-java-driver/commit/dd5b36bfd1aa63d893edfe4f024fd4831bc2d0fb&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-java-driver/commit/dd5b36bfd1aa63d893edfe4f024fd4831bc2d0fb&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="892099" author="jeff.yemin" created="Sat, 18 Apr 2015 10:48:23 +0000"  >&lt;p&gt;The driver will only discover the other members of the replica set if you use the MongoClient constructor that takes a List of ServerAddress instances.&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;m = &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;new&lt;/span&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; MongoClient(Arrays.asList(&lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;new&lt;/span&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; ServerAddress(host, port)), creds, options);&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;The way you have it now, the driver will only ever connect to the one MongoDB server running locally.&lt;/p&gt;</comment>
                            <comment id="892059" author="dharshanr@scalegrid.net" created="Sat, 18 Apr 2015 02:29:28 +0000"  >&lt;p&gt;Some of my mongo replicas run locally on the application box and the application connects locally using 127.0.0.1. This is the reason I just use one address instead of multiple hosts. Either way it seems possible that you can discover the rest of the servers even if just one server is specified.&lt;/p&gt;</comment>
                            <comment id="892048" author="jeff.yemin" created="Sat, 18 Apr 2015 01:16:37 +0000"  >&lt;p&gt;OK, we can reproduce this.  Thanks for the information.&lt;/p&gt;

&lt;p&gt;Can you tell us though why you&apos;re directly connecting to a secondary rather than specifying multiple hosts?&lt;/p&gt;</comment>
                            <comment id="891963" author="dharshanr@scalegrid.net" created="Fri, 17 Apr 2015 21:42:15 +0000"  >&lt;p&gt;Hi Craig,&lt;/p&gt;

&lt;p&gt;The operations I tried was to list collections&lt;/p&gt;

&lt;p&gt;                MongoDatabase db = m.getDatabase(&quot;test&quot;);&lt;br/&gt;
                for(String name: db.listCollectionNames())&lt;/p&gt;
                {
                    Logger.info(context + &quot;Listed Collection %s&quot;, name);
                }
&lt;p&gt;Another thing I noticed that it starts to work when I pass a list of hosts instead of a single host. The reason I pass a single host is that I have code running on the secondary machine that connects to 127.0.0.1.&lt;/p&gt;

&lt;p&gt;Hope that helps.&lt;/p&gt;</comment>
                            <comment id="891384" author="craiggwilson" created="Fri, 17 Apr 2015 12:57:18 +0000"  >&lt;p&gt;Hi Darshan,&lt;/p&gt;

&lt;p&gt;Some operations in MongoDB don&apos;t honor read preference, particularly write commands. Could you provide the code for the operation that is failing?&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="246716">JAVA-2081</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|hs1uiv:</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_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="485">Java Sprint 18</customfieldvalue>

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