<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 22:00:54 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>[CXX-958] Am I supposed to create the instance/connection once and pass it to every function I write?</title>
                <link>https://jira.mongodb.org/browse/CXX-958</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;Using mongoDB 2.2, every time I connected to the server within a function, I did this:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;boost::scoped_ptr&amp;lt;mongo::ScopedDbConnection&amp;gt; conn(mongo::ScopedDbConnection::getScopedDbConnection (&quot;localhost&quot; ) )&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Then I would use &lt;tt&gt;conn-&amp;gt;get()&lt;/tt&gt; and when done &lt;tt&gt;conn-&amp;gt;done()&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;In 3.3.5, I am doing this within each function:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;mongocxx::instance inst{}; mongocxx::client conn{mongocxx::uri&lt;/tt&gt;}&lt;/p&gt;

&lt;p&gt;This is, apparently wrong to do this every time I want to make a connection. The first time, it works perfectly. The server window outputs: &lt;/p&gt;

&lt;p&gt;&lt;tt&gt;connection accepted from 127.0.0.1:57896 #30 (2 connections now open)&lt;/tt&gt; &lt;/p&gt;

&lt;p&gt;and dutifully ends the connection at the end of the function block &lt;/p&gt;

&lt;p&gt;&lt;tt&gt;end connection 127.0.0.1:57896 (1 connection now open)&lt;/tt&gt;. &lt;/p&gt;

&lt;p&gt;(The 1 connection is the mongo shell). But when I repeat this in a subsequent block and try a command, it throws an exception: &lt;/p&gt;

&lt;p&gt;&lt;tt&gt;No suitable servers found (`serverSelectionTryOnce` set): &lt;span class=&quot;error&quot;&gt;&amp;#91;Failed to resolve &amp;#39;localhost&amp;#39;&amp;#93;&lt;/span&gt;: generic server error.&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;So, am I supposed to create the instance/connection once and pass it to every function I write (since globals are evil)?   &lt;/p&gt;</description>
                <environment>Windows 10&lt;br/&gt;
MS VS 2015&lt;br/&gt;
MongoDB 3.3.5&lt;br/&gt;
MongoDB C++11 Driver 3.0.1</environment>
        <key id="296701">CXX-958</key>
            <summary>Am I supposed to create the instance/connection once and pass it to every function I write?</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="5" iconUrl="https://jira.mongodb.org/images/icons/priorities/trivial.svg">Trivial - P5</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="-1">Unassigned</assignee>
                                    <reporter username="therefore">George Thompson</reporter>
                        <labels>
                    </labels>
                <created>Sat, 25 Jun 2016 21:10:52 +0000</created>
                <updated>Wed, 11 Sep 2019 19:06:29 +0000</updated>
                            <resolved>Sun, 26 Jun 2016 12:36:40 +0000</resolved>
                                    <version>3.0.1</version>
                                                    <component>Implementation</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="1306823" author="therefore" created="Sun, 26 Jun 2016 18:04:48 +0000"  >&lt;p&gt;Thanks Andrew. &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-890&quot; title=&quot;Add an example that shows how to manage a long-lived instance object&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-890&quot;&gt;&lt;del&gt;CXX-890&lt;/del&gt;&lt;/a&gt; and the Google Group discussion helped clarify what the instance class does. I have to admit to some confusion.&lt;/p&gt;</comment>
                            <comment id="1306759" author="acm" created="Sun, 26 Jun 2016 12:34:14 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=therefore&quot; class=&quot;user-hover&quot; rel=&quot;therefore&quot;&gt;therefore&lt;/a&gt; - That is correct, you only need (and should not create more than) one instance of the instance class. Please note that we are expecting to make some changes to how this works in the upcoming &lt;a href=&quot;https://jira.mongodb.org/issues/?jql=project%20%3D%20CXX%20AND%20fixVersion%20%3D%203.0.2%20ORDER%20BY%20status%20ASC&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;3.0.2&lt;/a&gt; release, though we have not entirely worked out what will change. Please see &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-890&quot; title=&quot;Add an example that shows how to manage a long-lived instance object&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-890&quot;&gt;&lt;del&gt;CXX-890&lt;/del&gt;&lt;/a&gt; for background.&lt;/p&gt;</comment>
                            <comment id="1306689" author="therefore" created="Sun, 26 Jun 2016 00:55:46 +0000"  >&lt;p&gt;I understand. I only need the instance in the main program. It works fine now.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="347240">CXX-1196</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|hsmwcn:</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="1064">Platforms 16 (06/24/16)</customfieldvalue>

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