<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:35: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>[GODRIVER-1031] mongo.Connect takes a context for no purpose</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-1031</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;The mongo.Connect function&#160;&lt;a href=&quot;https://godoc.org/go.mongodb.org/mongo-driver/mongo#Connect&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#Connect&lt;/a&gt;&#160;takes a context. However it does not seem to do anything with it: &lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/blob/master/mongo/client.go#L101&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/blob/master/mongo/client.go#L101&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;By taking context, it leads one to believe that the connect method should be request-scoped as per Golang&apos;s official documentation&#160;&lt;a href=&quot;https://golang.org/pkg/context/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://golang.org/pkg/context/&lt;/a&gt;&#160;. Instead, according to mongo&apos;s tutorial&#160;&lt;a href=&quot;https://www.mongodb.com/blog/post/mongodb-go-driver-tutorial&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://www.mongodb.com/blog/post/mongodb-go-driver-tutorial&lt;/a&gt;&#160;it says&#160;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;It is best practice to keep a client that is connected to MongoDB around so that the application can make use of connection pooling - you don&apos;t want to open and close a connection for each query. However, if your application no longer requires a connection, the connection can be closed with client.Disconnect() like so:&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;You can see how the documentation and the use of context creates a really confusing understanding of where the client.Connect() method is supposed to live and how it&apos;s supposed to be handled.&lt;/p&gt;

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

&lt;p&gt;First I realized that using client.Connect() in a request scope will cause an error because there can be multiple requests and client.Connect() returns an error if the client is already connected. Then I looked at the source code and realized context isn&apos;t actually being used.&lt;/p&gt;

&lt;p&gt;Now I connect once with an ad-hoc context, and share that connection for all requests. I believe that is the correct usage. But the documentation and tutorial does not make it clear&lt;/p&gt;

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

&lt;p&gt;Request: Connect should not take a context unless it is supposed to be request scoped and unless it is being utilized in someway. Documentation and tutorials should make it more clear where an app should Connect&lt;/p&gt;</description>
                <environment></environment>
        <key id="763189">GODRIVER-1031</key>
            <summary>mongo.Connect takes a context for no purpose</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="3">Duplicate</resolution>
                                        <assignee username="kris.brandow@mongodb.com">Kristofer Brandow</assignee>
                                    <reporter username="qhenkart@gmail.com">Quest Henkart</reporter>
                        <labels>
                    </labels>
                <created>Thu, 9 May 2019 12:47:45 +0000</created>
                <updated>Tue, 16 Nov 2021 16:58:55 +0000</updated>
                            <resolved>Thu, 9 May 2019 20:19:41 +0000</resolved>
                                                                    <component>Connections</component>
                    <component>Documentation</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="2240523" author="kris.brandow" created="Thu, 9 May 2019 20:19:07 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=qhenkart&quot; class=&quot;user-hover&quot; rel=&quot;qhenkart&quot;&gt;qhenkart&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;While it is true that the &lt;tt&gt;context.Context&lt;/tt&gt; is currently unused in the API having a &lt;tt&gt;context.Context&lt;/tt&gt; provided to a method like &lt;tt&gt;Connect&lt;/tt&gt; is correct usage because the &lt;tt&gt;context.Context&lt;/tt&gt; type is not used just for request scoped, as stated in the documentation for the &lt;tt&gt;context&lt;/tt&gt; package: &quot;Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes&quot;. In this case, if &lt;tt&gt;Connect&lt;/tt&gt; was synchronous and did network I/O then it would be appropriate to have a &lt;tt&gt;context.Context&lt;/tt&gt; for deadlines and cancellation signals.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="741304">GODRIVER-979</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </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|huo35r:</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>