<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:24:24 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>[DRIVERS-1969] Ignore read preference for $out/$merge on secondaries if any servers are pre-5.0</title>
                <link>https://jira.mongodb.org/browse/DRIVERS-1969</link>
                <project id="10980" key="DRIVERS">Drivers</project>
                    <description>&lt;p&gt;Currently the specification says:&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;- If an explicit (i.e. per-operation) read preference is specified for an&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;  aggregation with a write stage, drivers MUST attempt to use it. If that would&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;  result in a pre-5.0, secondary server being selected, drivers MUST instead&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;  select a server using a primary read preference.&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;- If no explicit read preference is specified but a default read preference is&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;  available to inherit (e.g. from the Collection), drivers MUST attempt to use&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;  it. If that would result in a pre-5.0, secondary server being selected,&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;  drivers MUST instead select a server using a primary read preference.&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;Defining it precisely in terms of available and eligible servers (the language of the server selection specification) would be more prescriptive and reduce differences in driver implementations.  Something like this:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   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;If an explicit (i.e. per-operation) or default (i.e., specified on a collection object) &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;read preference is specified for an aggregation with a write stage, &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;drivers use this logic to determine the list of eligible servers to consider:&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;&amp;nbsp;&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;If there are any *available* pre-5.0 servers, drivers MUST fall back to using primary &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;read preference to determine the list of *eligible* servers.  &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;Otherwise, drivers MUST apply the read preference to determine the list of *eligible* servers.&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;Examples (all with secondary read preference): &lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;a 5.0 primary and no secondaries -&amp;gt; apply read preference (no eligible servers)&lt;/li&gt;
	&lt;li&gt;a 5.0 primary and a 5.0 secondary -&amp;gt; apply read preference (one eligible server)&lt;/li&gt;
	&lt;li&gt;no available servers -&amp;gt; apply read preference (no eligible servers)&lt;/li&gt;
	&lt;li&gt;a 4.4 primary and a 5.0 secondary -&amp;gt; fallback to primary (one eligible server)&lt;/li&gt;
&lt;/ol&gt;



</description>
                <environment></environment>
        <key id="1913549">DRIVERS-1969</key>
            <summary>Ignore read preference for $out/$merge on secondaries if any servers are pre-5.0</summary>
                <type id="14901" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14700&amp;avatarType=issuetype">Spec Change</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="jmikola@mongodb.com">Jeremy Mikola</assignee>
                                    <reporter username="jeff.yemin@mongodb.com">Jeffrey Yemin</reporter>
                        <labels>
                            <label>size-small</label>
                            <label>spec-change</label>
                    </labels>
                <created>Fri, 29 Oct 2021 21:21:50 +0000</created>
                <updated>Fri, 20 May 2022 23:33:03 +0000</updated>
                            <resolved>Fri, 25 Mar 2022 19:49:38 +0000</resolved>
                                                        <component>CRUD</component>
                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="4180568" author="xgen-internal-githook" created="Wed, 10 Nov 2021 15:50:00 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Jeremy Mikola&apos;, &apos;email&apos;: &apos;jmikola@gmail.com&apos;, &apos;username&apos;: &apos;jmikola&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DRIVERS-1969&quot; title=&quot;Ignore read preference for $out/$merge on secondaries if any servers are pre-5.0&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DRIVERS-1969&quot;&gt;&lt;del&gt;DRIVERS-1969&lt;/del&gt;&lt;/a&gt;: Revise rules for $out/$merge read preferences (#1095)&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/DRIVERS-1969&quot; title=&quot;Ignore read preference for $out/$merge on secondaries if any servers are pre-5.0&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DRIVERS-1969&quot;&gt;&lt;del&gt;DRIVERS-1969&lt;/del&gt;&lt;/a&gt;: Revise rules for $out/$merge read preferences&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Only fall back to a primary read preference if there is evidence that the driver is connected to a pre-5.0 server.&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Assume LoadBalanced topology has all 5.0+ server(s)&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/specifications/commit/747b7480c47900827ff2b64f23c2a14636803d1a&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/specifications/commit/747b7480c47900827ff2b64f23c2a14636803d1a&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</comment>
                            <comment id="4173610" author="jmikola@gmail.com" created="Sun, 7 Nov 2021 18:32:32 +0000"  >&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/specifications/pull/1095&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/specifications/pull/1095&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4166832" author="jmikola@gmail.com" created="Wed, 3 Nov 2021 14:31:20 +0000"  >&lt;blockquote&gt;&lt;p&gt;but is there any other help I can still provide here?&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Just to close the loop, &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=david.storch&quot; class=&quot;user-hover&quot; rel=&quot;david.storch&quot;&gt;david.storch&lt;/a&gt; and I sorted this out over Slack. He confirmed that mongos read preference behavior wasn&apos;t touched for PM-1770, so my earlier question about &quot;what would mongos do&quot; isn&apos;t really applicable. It&apos;s just going to enforce the &lt;tt&gt;$readPreference&lt;/tt&gt; provided by the driver.&lt;/p&gt;</comment>
                            <comment id="4165416" author="david.storch" created="Tue, 2 Nov 2021 22:37:27 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jmikola&quot; class=&quot;user-hover&quot; rel=&quot;jmikola&quot;&gt;jmikola&lt;/a&gt;&#160;I&apos;m not sure I follow all the details of this thread, but is there any other help I can still provide here? Jeff&apos;s understanding is correct that it is never legal to have a cluster with a 5.0 mongos but a pre-5.0 mongod. In fact, I&apos;m pretty sure that a 5.0 mongos would refuse to connect to a pre-5.0 mongod.&lt;/p&gt;</comment>
                            <comment id="4165361" author="kaitlin.mahar" created="Tue, 2 Nov 2021 22:06:24 +0000"  >&lt;p&gt;Correct, the Swift driver delegates to &lt;tt&gt;mongoc_database_aggregate&lt;/tt&gt; and &lt;tt&gt;mongoc_collection_aggregate&lt;/tt&gt; for aggregation support.&lt;/p&gt;</comment>
                            <comment id="4165284" author="jmikola@gmail.com" created="Tue, 2 Nov 2021 21:32:59 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jeff.yemin&quot; class=&quot;user-hover&quot; rel=&quot;jeff.yemin&quot;&gt;jeff.yemin&lt;/a&gt; and I met earlier today to discuss this and came up with the following approach, which I think will more closely align with &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=rstam&quot; class=&quot;user-hover&quot; rel=&quot;rstam&quot;&gt;rstam&lt;/a&gt;&apos;s table:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If there are one or more available servers and at least one of those is pre-5.0 (i.e. there is evidence of a pre-5.0 server), do &lt;em&gt;not&lt;/em&gt; use the explicit/inherited read preference and instead fall back to using a primary read preference.&lt;/p&gt;

&lt;p&gt;If there are no available servers, attempt to use the explicit/inherited read preference.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;This means that a 5.0+ secondary in a cluster containing one or more pre-5.0 servers will never be utilized; however, it also avoids the earlier BC issue where a replica set consisting of a lone pre-5.0 primary would not be used as a fall back and users would instead encounter a server selection failure.&lt;/p&gt;

&lt;p&gt;As for the implementation, Jeff suggests that this can be implemented within the &quot;Find suitable servers by topology type and operation type&quot; step in the server selection algorithm (&lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#server-selection-algorithm&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;step 3 for multi-thread/async&lt;/a&gt;, &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#single-threaded-server-selection&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;step 6 for single-threaded&lt;/a&gt;).&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;There is still a potential issue for drivers downstream of libmongoc (e.g. PHPLIB), which utilize &lt;a href=&quot;http://mongoc.org/libmongoc/current/mongoc_client_select_server.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;&lt;tt&gt;mongoc_client_select_server&lt;/tt&gt;&lt;/a&gt;. That API only takes a &lt;tt&gt;for_writes&lt;/tt&gt; boolean and an optional read preference. An alternative API would need to be introduced that also takes an optional wire version, such that the following logic could be enforced:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If any servers have wire version &amp;lt; 13, select a primary (i.e. &lt;tt&gt;for_writes=true&lt;/tt&gt;); otherwise, use the provided read preference.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Jeff and I discussed how PHP could conceivably work around this without requiring API changes in libmongoc. If we were to stick with the current two-attempt approach (i.e. only fall back to a primary if the first attempt returns a pre-5.0 secondary), there would still be the BC break for a RS consisting of a lone pre-5.0 primary. I&apos;ll continue to give that some thought, but I&apos;d very much like to avoid an API change in libmongoc just for this feature.&lt;/p&gt;

&lt;p&gt;I don&apos;t believe Swift is affected, as they may delegate to &lt;a href=&quot;http://mongoc.org/libmongoc/current/mongoc_collection_aggregate.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;&lt;tt&gt;mongoc_collection_aggregate&lt;/tt&gt;&lt;/a&gt; (or the equivalent database method) instead of handling server selection directly as PHPLIB does (cc: &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=kaitlin.mahar&quot; class=&quot;user-hover&quot; rel=&quot;kaitlin.mahar&quot;&gt;kaitlin.mahar&lt;/a&gt;).&lt;/p&gt;</comment>
                            <comment id="4161902" author="jmikola@gmail.com" created="Mon, 1 Nov 2021 21:33:08 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=david.storch&quot; class=&quot;user-hover&quot; rel=&quot;david.storch&quot;&gt;david.storch&lt;/a&gt;: Given the complexities of server selection discussed above, can you clarify how mongos handles server selection for executing $out/$merge pipelines on secondaries? Note that for a pre-5.0 mongos, the driver would always send RP(primary) to mongos, which isn&apos;t controversial. I&apos;m specifically curious about the case where the driver forwards a read preference to a 5.0+ mongos and the shard(s) have any of the aforementioned set of servers.&lt;/p&gt;

&lt;p&gt;Edit: &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jeff.yemin&quot; class=&quot;user-hover&quot; rel=&quot;jeff.yemin&quot;&gt;jeff.yemin&lt;/a&gt;&#160;pointed out that this may not be an issue for mongos since the upgrade process requires that shards be upgraded &lt;em&gt;before&lt;/em&gt; mongos. Given that, any 5.0+ mongos potentially receiving a non-primary read preference could be expected to only have 5.0+ nodes in its shard(s).&lt;/p&gt;

&lt;p&gt;I was specifically curious about mongos&apos; behavior when a shard is a replica set consisting of only a single primary. I suppose in this case, a 5.0+ mongos could always honor the read preference either way. So RP(secondary) would simply result in a server selection failure and there&apos;s never a question of whether mongos would decide to fall back to the lone primary. And the aforementioned case of there only being a pre-5.0 primary isn&apos;t applicable, since that would never exist behind a 5.0+ mongos (per the upgrade order).&lt;/p&gt;</comment>
                            <comment id="4161573" author="jmikola@gmail.com" created="Mon, 1 Nov 2021 19:40:15 +0000"  >&lt;p&gt;I&apos;ll start by addressing examples in the issue description:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Examples (all with secondary read preference):&lt;/p&gt;

&lt;p&gt;1. a 5.0 primary and no secondaries -&amp;gt; apply read preference (no eligible servers)&lt;br/&gt;
 2. a 5.0 primary and a 5.0 secondary -&amp;gt; apply read preference (one eligible server)&lt;br/&gt;
 3. no available servers -&amp;gt; apply read preference (no eligible servers)&lt;br/&gt;
 4. a 4.4 primary and a 5.0 secondary -&amp;gt; fallback to primary (one eligible server)&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The existing text in &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#read-preferences-and-server-selection&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Read preferences and server selection&lt;/a&gt; (from &lt;a href=&quot;https://jira.mongodb.org/browse/DRIVERS-823&quot; title=&quot;Support $merge and $out executing on secondaries&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DRIVERS-823&quot;&gt;DRIVERS-823&lt;/a&gt;) instructs drivers to first apply any explicit/inherited read preference and, iff a pre-5.0 secondary is selected, fall back to a primary.&lt;/p&gt;

&lt;p&gt;With respect to the examples above, the fourth example should result in the 5.0 secondary being utilized.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;My current interpretation of the spec with respect to the table in the previous comment is as follows:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Row 4 (P-none, S-none): no servers are available so any RP results in a server selection failure&lt;/li&gt;
	&lt;li&gt;Row 5 (P-none, S4): neither a primary nor an 5.0+ secondary is available, so any RP results in a server selection failure&lt;/li&gt;
	&lt;li&gt;&lt;b&gt;Row 6 (P4, S-none):&lt;/b&gt; P4 will be selected for most RPs; however, RP(secondary) will result in a server selection failure because a pre-5.0 secondary is never selected to warrant fall back behavior. This is potentially a behavioral BC break&lt;/li&gt;
	&lt;li&gt;Row 7 (P4, S4): P4 will always be selected, either directly or as a fall back after S4 is selected&lt;/li&gt;
	&lt;li&gt;&lt;b&gt;Row 8 (P4, S5):&lt;/b&gt; P4 will always be selected for RP(primary) or RP(primaryPreferred). S5 will always be selected for RP(secondary) or RP(secondaryPreferred). RP(nearest) is non-deterministic.&lt;/li&gt;
	&lt;li&gt;&lt;b&gt;Row 9 (P4, S4+S5):&lt;/b&gt; P4 will always be selected for RP(primary) or RP(primaryPreferred). Other RPs are non-deterministic, since S4 could be selected and warrant falling back to P4.&lt;/li&gt;
	&lt;li&gt;Row 10 (P5, S4): P5 will always be selected, either directly or as a fall back after S4 is selected&lt;/li&gt;
	&lt;li&gt;&lt;b&gt;Row 11 (P5, S4+S5):&lt;/b&gt; P5 will always be selected for RP(primary) or RP(primaryPreferred). Other RPs are non-deterministic, since S4 could be selected and warrant falling back to P5.&lt;/li&gt;
	&lt;li&gt;Row 13 (P-none, S5): RP(primary) always results in a server selection failure. For all other RPs, S5 will be selected&lt;/li&gt;
	&lt;li&gt;Row 14 (P5, S-none): RP(secondary) always results in a server selection failure. For all other RPs, P5 will be selected&lt;/li&gt;
	&lt;li&gt;Row 15 (P5, S5): P5 or S5 will be selected according to the RP. Only RP(nearest) is non-deterministic&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I&apos;ve bolded the lines where my interpretation differs from Robert&apos;s table.&lt;/p&gt;

&lt;p&gt;I realize this leads to more non-deterministic cases for mixed-version clusters; however, my intention was to allow drivers more flexibility given their server selection implementations. I did not want to require drivers to modify their &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#multi-threaded-server-selection-implementation&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;server selection algorithm&lt;/a&gt; just for this feature. Needing to consider whether &quot;all available servers are 5.0+&quot; would require more invasive changes.&lt;/p&gt;

&lt;p&gt;As-is, drivers using the one-attempt approach can use their existing algorithm and only fall back to a primary (bypassing a full second attempt) if a pre-5.0 secondary is selected. The two-attempt approach is not much different, but would be necessary for drivers that can&apos;t easily bypass selection to do the fall back (e.g. PHP atop libmongoc).&lt;/p&gt;

&lt;p&gt;The &quot;&lt;span class=&quot;error&quot;&gt;&amp;#91;potential&amp;#93;&lt;/span&gt; behavioral BC break&quot; scenario for Row 6 (P4, S-none) may need to be addressed regardless, as I didn&apos;t consider that in &lt;a href=&quot;https://jira.mongodb.org/browse/DRIVERS-823&quot; title=&quot;Support $merge and $out executing on secondaries&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DRIVERS-823&quot;&gt;DRIVERS-823&lt;/a&gt;. But I&apos;m not sure how we could easily handle that without invasive server selection changes to determine versions across all available servers in the topology. Without doing so, a (P4, S-none) cluster would be hard to distinguish from a (P4, S5) cluster where the secondaries are inaccessible.&lt;/p&gt;</comment>
                            <comment id="4158557" author="rstam" created="Fri, 29 Oct 2021 23:43:18 +0000"  >&lt;p&gt;I&apos;m trying to understand with precision how to select a server for $out (on replica sets) which has been confounding me.&lt;/p&gt;

&lt;p&gt;To make sure I properly understand exactly how server selection should work in every possible scenario I&apos;ve prepared the following table to describe my interpretation.&lt;/p&gt;

&lt;p&gt;the first two columns represent different cluster configurations&lt;br/&gt;
none means no available server&lt;br/&gt;
P4 and P5 mean a 4.x or 5.x primary&lt;br/&gt;
S4 and S5 mean a 4.x or 5.x secondary (possibly more than one)&lt;br/&gt;
error means no suitable server (server selector will keep trying and eventually timeout)&lt;br/&gt;
The cell at the intersection of a cluster configuration and ReadPreference indicates what server(s) will be selected&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/343247/343247_image-2021-10-29-16-41-37-013.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Rows 4-11 are all the &quot;fallback to primary&quot; scenarios&lt;/p&gt;

&lt;p&gt;Rows 13-15 are all the &quot;apply the read preference&quot; scenarios&lt;/p&gt;

&lt;p&gt;In English I would summarize this as:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;if there are &lt;b&gt;any&lt;/b&gt; available servers and &lt;b&gt;all&lt;/b&gt; available servers are 5.0+ apply the read preference&lt;/li&gt;
	&lt;li&gt;otherwise fallback to primary&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                                                <inwardlinks description="is depended on by">
                                        <issuelink>
            <issuekey id="1612689">PYTHON-2554</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10620">
                    <name>Issue split</name>
                                            <outwardlinks description="split to">
                                        <issuelink>
            <issuekey id="1920652">PHPLIB-760</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920645">CDRIVER-4224</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920647">CSHARP-3957</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920646">CXX-2414</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920648">GODRIVER-2220</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920649">JAVA-4396</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920654">MOTOR-859</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920650">NODE-3752</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920653">PYTHON-3012</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920655">RUBY-2841</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1920656">RUST-1097</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="1128616">DRIVERS-823</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1912509">JAVA-4380</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="1901237">DRIVERS-1955</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="343247" name="image-2021-10-29-16-41-37-013.png" size="27853" author="robert@mongodb.com" created="Fri, 29 Oct 2021 23:41:37 +0000"/>
                    </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_17052" key="com.atlassian.jira.plugin.system.customfieldtypes:textarea">
                        <customfieldname>Downstream Changes Summary</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>&lt;p&gt;In &lt;a href=&quot;https://github.com/mongodb/specifications/commit/747b7480c47900827ff2b64f23c2a14636803d1a&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongodb/specifications@747b748&lt;/a&gt;, the rules were applying a read preference for aggregations using &lt;tt&gt;$out&lt;/tt&gt; and &lt;tt&gt;$merge&lt;/tt&gt; was changed. Previously, drivers were instructed to attempt using the read preference and only fall back to a primary if a pre-5.0 secondary was selected.&lt;/p&gt;

&lt;p&gt;This was changed to require drivers to always disregard the read preference if there is &lt;em&gt;any&lt;/em&gt; evidence of a pre-5.0 server. If there are either no available servers or all servers are 5.0+ (or load balanced, where we assume 5.0+), drivers can utilize the read preference.&lt;/p&gt;

&lt;p&gt;Spec tests have not been changed, as this clarification really only changes behavior for mixed version clusters or a replica set consisting of a single pre-5.0 primary, neither of which are tested.&lt;/p&gt;</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10951" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Driver Changes</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10748"><![CDATA[Needed]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_23952" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Driver Compliance</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[<style type='text/css'>
         #scriptField, #scriptField *{
                border: 1px solid black;
            }

            #scriptField{
                border-collapse: collapse;
            }

            #scriptField td {
                text-align: center; /* Center-align text in table cells */
            }

            #scriptField td.key {
                text-align: left; /* Left-align text in the Key column */
            }

            #scriptField a {
                text-decoration: none; /* Remove underlines from links */
                border: none; /* Remove border from links */
            }
            
            /* Add green background color to cells with FixVersion */
            #scriptField td.hasFixVersion {
                background-color: #00FF00; /* Green color code */
            }

            /* Center-align the first row headers */
            #scriptField th {
                text-align: center;
            }
        </style>
<table id='scriptField'>
  <tr>
    <th>Key</th>
    <th>Status/Resolution</th>
    <th>FixVersion</th>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/CDRIVER-4224'>CDRIVER-4224</a>
    </td>
    <td>Done</td>
    <td class='hasFixVersion'>1.21.0</td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/CXX-2414'>CXX-2414</a>
    </td>
    <td>Works as Designed</td>
    <td class=''></td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/CSHARP-3957'>CSHARP-3957</a>
    </td>
    <td>Done</td>
    <td class='hasFixVersion'>2.15.0</td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/GODRIVER-2220'>GODRIVER-2220</a>
    </td>
    <td>Done</td>
    <td class='hasFixVersion'>1.8.0</td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/JAVA-4396'>JAVA-4396</a>
    </td>
    <td>Duplicate</td>
    <td class=''></td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/NODE-3752'>NODE-3752</a>
    </td>
    <td>Works as Designed</td>
    <td class=''></td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/PHPLIB-760'>PHPLIB-760</a>
    </td>
    <td>Fixed</td>
    <td class='hasFixVersion'>1.10.1</td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/PYTHON-3012'>PYTHON-3012</a>
    </td>
    <td>Duplicate</td>
    <td class=''></td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/MOTOR-859'>MOTOR-859</a>
    </td>
    <td>Duplicate</td>
    <td class=''></td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/RUBY-2841'>RUBY-2841</a>
    </td>
    <td>Fixed</td>
    <td class='hasFixVersion'>2.17.0</td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/RUST-1097'>RUST-1097</a>
    </td>
    <td>Duplicate</td>
    <td class=''></td>
  </tr>
  <tr>
    <td class='key'>
      <a href='https://jira.mongodb.org/browse/SWIFT-1412'>SWIFT-1412</a>
    </td>
    <td>Duplicate</td>
    <td class=''></td>
  </tr>
</table>]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_21553" key="com.atlassian.jira.plugin.system.customfieldtypes:labels">
                        <customfieldname>Quarter</customfieldname>
                        <customfieldvalues>
                                        <label>FY22Q4</label>
    
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hzrua7:</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>