<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:34:21 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-504] how to NewClient with SCRAM-SHA-1, usename, password and database</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-504</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;package main&lt;/p&gt;

&lt;p&gt;import (&lt;br/&gt;
	&quot;context&quot;&lt;br/&gt;
	&quot;fmt&quot;&lt;br/&gt;
	&quot;github.com/apex/log&quot;&lt;br/&gt;
	&quot;github.com/mongodb/mongo-go-driver/bson&quot;&lt;br/&gt;
	&quot;github.com/mongodb/mongo-go-driver/mongo&quot;&lt;br/&gt;
	&quot;github.com/mongodb/mongo-go-driver/mongo/clientopt&quot;&lt;br/&gt;
	&quot;time&quot;&lt;br/&gt;
)&lt;/p&gt;

&lt;p&gt;func main() &lt;/p&gt;
{
	f1()
}

&lt;p&gt;func f1() {&lt;br/&gt;
	appname := clientopt.AppName(&quot;myapp&quot;)&lt;br/&gt;
	conTimeout := clientopt.ConnectTimeout(time.Second)&lt;br/&gt;
	sockTimout := clientopt.SocketTimeout(time.Second)&lt;br/&gt;
	serverSTimeout := clientopt.ServerSelectionTimeout(time.Second * 3)&lt;br/&gt;
	single := clientopt.Single(true)&lt;br/&gt;
	auth := clientopt.Auth(clientopt.Credential&lt;/p&gt;
{AuthMechanism: &quot;SCRAM-SHA-1&quot;,
		AuthSource: &quot;xxx&quot;,
		Username:   &quot;xxx&quot;, Password: &quot;as@xxx&quot;}
&lt;p&gt;)&lt;/p&gt;

&lt;p&gt;	client, err := mongo.NewClientWithOptions(&quot;mongodb://localhost:27017&quot;, single, serverSTimeout, appname, sockTimout, conTimeout, auth)&lt;br/&gt;
	if err != nil &lt;/p&gt;
{
		log.WithError(err).Fatal(&quot;error connecting&quot;)
	}&lt;br/&gt;
	err = client.Connect(context.Background())&lt;br/&gt;
	if err != nil {
		log.WithError(err).Fatal(&quot;error connecting&quot;)
	}

&lt;p&gt;	fmt.Println(client.ListDatabases(context.Background(), nil))&lt;/p&gt;

&lt;p&gt;	collection := client.Database(&quot;xxx&quot;).Collection(&quot;test&quot;)&lt;/p&gt;

&lt;p&gt;	cur, err := collection.Find(context.Background(), nil)&lt;br/&gt;
	if err != nil &lt;/p&gt;
{
		log.WithError(err).Fatal(&quot;failed to find collection&quot;)
	}

&lt;p&gt;	defer cur.Close(context.Background())&lt;br/&gt;
	for cur.Next(context.Background()) {&lt;br/&gt;
		elem := bson.NewDocument()&lt;br/&gt;
		err := cur.Decode(elem)&lt;br/&gt;
		if err != nil &lt;/p&gt;
{
			log.WithError(err).Fatal(&quot;failed to decode element&quot;)
		}
&lt;p&gt;		// do something with elem....&lt;br/&gt;
		fmt.Printf(&quot;%v\n&quot;, elem.ToExtJSON(true))&lt;br/&gt;
	}&lt;br/&gt;
	if err := cur.Err(); err != nil &lt;/p&gt;
{
		log.WithError(err).Fatal(&quot;failed to get cursor&quot;)
	}

&lt;p&gt;}&lt;/p&gt;


&lt;p&gt;than go run main.go, it outputs&lt;/p&gt;

&lt;p&gt;command-line-arguments&lt;/p&gt;
{[] 0}
&lt;p&gt; auth error: sasl conversation error: unable to authenticate using mechanism &quot;SCRAM-SHA-1&quot;: Authentication failed.&lt;br/&gt;
2018/07/20 17:48:35 fatal failed to find collection error=auth error: sasl conversation error: unable to authenticate using mechanism &quot;SCRAM-SHA-1&quot;: Authentication failed.&lt;br/&gt;
exit status 1&lt;/p&gt;

&lt;p&gt;how to make it works&lt;/p&gt;

</description>
                <environment>linux </environment>
        <key id="573904">GODRIVER-504</key>
            <summary>how to NewClient with SCRAM-SHA-1, usename, password and database</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="kris.brandow@mongodb.com">Kristofer Brandow</assignee>
                                    <reporter username="jackylee">orange.jackylee</reporter>
                        <labels>
                    </labels>
                <created>Fri, 20 Jul 2018 10:07:08 +0000</created>
                <updated>Wed, 11 Sep 2019 18:35:20 +0000</updated>
                            <resolved>Fri, 27 Jul 2018 10:58:49 +0000</resolved>
                                    <version>0.0.9</version>
                                                    <component>Authentication</component>
                    <component>Connections</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="1952951" author="jackylee" created="Sat, 21 Jul 2018 08:40:19 +0000"  >&lt;p&gt;thank you kris brandow, after connection string add database, it works. &lt;/p&gt;</comment>
                            <comment id="1952200" author="kris.brandow" created="Fri, 20 Jul 2018 13:45:15 +0000"  >&lt;p&gt;Hello &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jackylee&quot; class=&quot;user-hover&quot; rel=&quot;jackylee&quot;&gt;jackylee&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Does your connection string have a database in it? For instance, if your connection string is &quot;mongodb://localhost:27017/foo&quot; then &quot;foo&quot; would be the database.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;/p&gt;

&lt;p&gt;Kris&lt;/p&gt;</comment>
                    </comments>
                    <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|httqef:</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>