[DOCS-13739] Go driver getting started instructions do not work Created: 29/Jun/20  Updated: 29/Oct/23  Resolved: 02/Jul/20

Status: Closed
Project: Documentation
Component/s: drivers
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Rachelle Palmer Assignee: Christopher Cho
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 3 years, 31 weeks, 6 days ago
Story Points: 2

 Description   

Description

page: https://docs.mongodb.com/drivers/go/

The example to connect to Atlas is not possible to get working, users receive a code error:

./goproj.go:14:2: client declared but not used

It looks like I need to read "Usage" on Github to see whats missing. Which, if I was a newer MongoDB customer this would be a pain, especially if I just wanted to test connecting or wanted quick bootstrap code like our other driver docs offer. This instruction is so barebones, _you actually have to read GitHub. _

You have to add an additional option for client in this case.
I added this:
err = client.Ping(ctx, readpref.Primary())
This satisfied the client variable use.
Because without, you get the error above. There might be other ways that are better, unclear.

Scope of changes

Impact to Other Docs

MVP (Work and Date)

Resources (Scope or Design Docs, Invision, etc.)



 Comments   
Comment by Githook User [ 02/Jul/20 ]

Author:

{'name': 'Chris Cho', 'email': 'chris.cho@mongodb.com', 'username': 'ccho-mongodb'}

Message: Docs 13739 fix go connection (#651)

Comment by Githook User [ 02/Jul/20 ]

Author:

{'name': 'Chris Cho', 'email': 'chris.cho@mongodb.com', 'username': 'ccho-mongodb'}

Message: DOCS-13739: add defers to the code snippets in the README (#437)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/3191cb10e4b892d21cac60e034908c9534ceb286

Comment by Christopher Cho [ 30/Jun/20 ]

Ecosystem Docs:

https://github.com/mongodb/docs-ecosystem/pull/651

Cloud Docs:

https://github.com/10gen/cloud-docs/pull/1703

Go Driver README:

https://github.com/mongodb/mongo-go-driver/pull/437

Comment by Divjot Arora (Inactive) [ 30/Jun/20 ]

Yes, you do have to use the client variable to silence the Go compilation error. I'd recommend changing the example to also defer a Disconnect call:

client, err := mongo.Connect(...)
if err != nil {
    panic(err)
}
 
// Defer a function to call Disconnect and check the error. In many cases,
// it's possible that the application may only want to log a warning rather 
// than panic if Disconnect fails.
defer func() {
    if err = client.Disconnect(ctx); err != nil {
        panic(err)
    }
}()
 
if err := client.Ping(ctx, readpref.Primary()); err != nil {
    panic(err)
}

Generated at Thu Feb 08 08:08:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.