<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:36:57 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>[GODRIVER-1703] Change Session examples to use transactions</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-1703</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;&lt;b&gt;Updated Description&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo@v1.3.5?tab=doc#example-Client.UseSessionWithOptions&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo@v1.3.5?tab=doc#example-Client.UseSessionWithOptions&lt;/a&gt;&#160;uses the DefaultReadConcern option, which only applies to transactions started within a session, but does not start a transaction. This is confusing, so we should change the example to start a transaction. We should also verify that other sessions-related examples don&apos;t do the same thing.&lt;/p&gt;

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

&lt;p&gt;&lt;b&gt;Previous Description&lt;/b&gt;&#160;&lt;/p&gt;

&lt;p&gt;Using a session with readpref=Secondary results in queries against the primary.&lt;/p&gt;

&lt;p&gt;Please see the attached test case that demonstrates the issue.&lt;/p&gt;

&lt;p&gt;My setup:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Local Replica Set called &quot;ci&quot; with two nodes: port 27017 is the primary, 27016 is the secondary&lt;/li&gt;
	&lt;li&gt;RS config sets the secondary with priority=0 so it doesn&apos;t become primary&lt;/li&gt;
	&lt;li&gt;I use toxiproxy to artificially add latency from primary to secondary. This isn&apos;t necessary, but makes the test more reliably reproducible.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Debugging FindOne() it seems like the read preference setting for the session is ignored if not inside a transaction. Setting the read preference on the Collection makes the test pass.&lt;/p&gt;

&lt;p&gt;I&apos;m roughly following the example from&#160;&lt;a href=&quot;https://godoc.org/go.mongodb.org/mongo-driver/mongo#Client.UseSession&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://godoc.org/go.mongodb.org/mongo-driver/mongo#Client.UseSession&lt;/a&gt;&#160;. Am I using the API incorrectly?&lt;/p&gt;</description>
                <environment>go 1.14 on mac os x</environment>
        <key id="1420716">GODRIVER-1703</key>
            <summary>Change Session examples to use transactions</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="13201">Fixed</resolution>
                                        <assignee username="divjot.arora@mongodb.com">Divjot Arora</assignee>
                                    <reporter username="dv@glyphy.com">D V</reporter>
                        <labels>
                    </labels>
                <created>Fri, 24 Jul 2020 22:07:33 +0000</created>
                <updated>Sat, 28 Oct 2023 11:38:05 +0000</updated>
                            <resolved>Thu, 13 Aug 2020 14:33:08 +0000</resolved>
                                    <version>1.3.5</version>
                                    <fixVersion>1.4.1</fixVersion>
                                    <component>Documentation</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="3336988" author="xgen-internal-githook" created="Thu, 13 Aug 2020 14:32:27 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Divjot Arora&apos;, &apos;email&apos;: &apos;divjot.arora@10gen.com&apos;, &apos;username&apos;: &apos;divjotarora&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-1703&quot; title=&quot;Change Session examples to use transactions&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-1703&quot;&gt;&lt;del&gt;GODRIVER-1703&lt;/del&gt;&lt;/a&gt; Update Sessions examples to use transactions (#478)&lt;br/&gt;
Branch: release/1.4&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/commit/8376d6d9f5d8c7efed178960a54ced0adf6cbb8c&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/commit/8376d6d9f5d8c7efed178960a54ced0adf6cbb8c&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3336985" author="xgen-internal-githook" created="Thu, 13 Aug 2020 14:31:28 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Divjot Arora&apos;, &apos;email&apos;: &apos;divjot.arora@10gen.com&apos;, &apos;username&apos;: &apos;divjotarora&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-1703&quot; title=&quot;Change Session examples to use transactions&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-1703&quot;&gt;&lt;del&gt;GODRIVER-1703&lt;/del&gt;&lt;/a&gt; Update Sessions examples to use transactions (#478)&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/commit/1c6ce243313adea74223d6f14539f18d938b5aa1&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/commit/1c6ce243313adea74223d6f14539f18d938b5aa1&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3334585" author="divjot.arora" created="Wed, 12 Aug 2020 14:35:38 +0000"  >&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/pull/478&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/pull/478&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3310809" author="divjot.arora" created="Tue, 28 Jul 2020 20:52:37 +0000"  >&lt;p&gt;Thanks for the documentation suggestions. I agree these would be helpful. The driver can&apos;t panic when the session is created because a user could be connected to a mixed-version deployment, where some subset of servers supports transactions, or the cluster could be upgraded/downgraded. To support such dynamic behavior, configurations like this have to be allowed. We can definitely clarify some of this in our docs, though. I&apos;ve put this ticket back into &quot;Investigating&quot; and will figure out what changes need to be made over the next few days.&lt;/p&gt;

&lt;p&gt;&amp;#8211; Divjot&lt;/p&gt;</comment>
                            <comment id="3310040" author="dv@glyphy.com" created="Tue, 28 Jul 2020 15:22:51 +0000"  >&lt;p&gt;Thanks, Divjot! That explains the behaviour.&lt;/p&gt;

&lt;p&gt;Do you think the documentation could be clarified a little? The example I was looking at (&lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo@v1.3.5?tab=doc#example-Client.UseSessionWithOptions&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo@v1.3.5?tab=doc#example-Client.UseSessionWithOptions&lt;/a&gt;) doesn&apos;t use a transaction, so that made it seem like it was enough to set the read preference and read concern on the Session. I think it would be clearer if the example included the use of a transaction make it&#160;explicitly mandatory. Also, maybe a sentence in&#160;&lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo@v1.3.5?tab=doc#Session&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo@v1.3.5?tab=doc#Session&lt;/a&gt;&#160;about this could help guide users in the right direction? Something like &quot;Setting read/write preference and concern on the Session requires the use of a Transaction to take effect&quot;?&lt;/p&gt;

&lt;p&gt;Personally, I would prefer the driver to panic if I tried to set anything on the Session that wasn&apos;t supported in a non-transactional context instead of silently ignoring it due to the difficulty of detecting the problem. This would have made it a lot easier for me to notice my misunderstanding of the API.&lt;/p&gt;</comment>
                            <comment id="3309706" author="divjot.arora" created="Tue, 28 Jul 2020 13:28:19 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=dv%40glyphy.com&quot; class=&quot;user-hover&quot; rel=&quot;dv@glyphy.com&quot;&gt;dv@glyphy.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;As documented at&#160;&lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo/options?tab=doc#SessionOptions&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo/options?tab=doc#SessionOptions&lt;/a&gt;, the &lt;tt&gt;DefaultReadPreference&lt;/tt&gt; option for a session controls the read preference used for transactions started within the session. Transactions are only supported on MongoDB servers 4.0 and higher. The only way to control the read preference for non-transactional operations is to set it on the Collection instance. I&apos;m going to close this ticket out as &quot;Works as Designed&quot; but feel free to leave another comment or open a new ticket if you have further questions.&lt;/p&gt;

&lt;p&gt;&amp;#8211; Divjot&lt;/p&gt;</comment>
                            <comment id="3302733" author="dv@glyphy.com" created="Fri, 24 Jul 2020 22:09:15 +0000"  >&lt;p&gt;Forgot to mention that I&apos;m using MongoDB 3.6.18.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="2096395">GODRIVER-2499</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="271352" name="session_test.go" size="1364" author="dv@glyphy.com" created="Fri, 24 Jul 2020 22:06:21 +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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr774n:</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>