-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Connections, Documentation
-
None
-
Environment:Docker pulling from github.com/mongodb/mongo-go-driver/mongo (latest)
You guys updated how you handle connections:
https://github.com/mongodb/mongo-go-driver/commit/32946b1f8b9412a6a94e68ff789575327bb257cf
but the documentation here:
https://godoc.org/github.com/mongodb/mongo-go-driver/mongo
and here:
https://github.com/mongodb/mongo-go-driver
is out of date.
It now needs to look something like something shown below (tested/compiles). Please update your docs or you will have a lot of confused people in the morning. I'll also update this SO: https://stackoverflow.com/questions/54778520/mongo-go-driver-failing-to-connect. Thanks!
package database
import(
"fmt"
"context"
"os"
"time"
"github.com/mongodb/mongo-go-driver/mongo"
"github.com/mongodb/mongo-go-driver/mongo/options"
)
func CreateConnectionHandler()(*mongo.Database, error){
fmt.Println("inside createConnection in database package")
godotenv.Load()
fmt.Println("in CreateConnectionHandler and SERVER_CONFIG: ")
fmt.Println(os.Getenv("SERVER_CONFIG"))
uri:=""
if os.Getenv("SERVER_CONFIG")=="kubernetes"{
fmt.Println("inside kubernetes db config")
uri = "mongodb://patientplatypus:SUPERSECRETPASSDOOTb@mongo-release-mongodb.default.svc.cluster.local:27017/platypusNEST?authMechanism=SCRAM-SHA-1"
}else if os.Getenv("SERVER_CONFIG")=="compose"{
fmt.Println("inside compose db config")
uri = "mongodb://datastore:27017"
}
client, err := mongo.NewClient(options.Client().ApplyURI(uri))
if err != nil {
fmt.Println("error: ", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
err = client.Connect(ctx)
if err != nil {
fmt.Println(err)
}
// ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
// client, err := mongo.Connect(ctx, uri)
// if err != nil {
// return nil, fmt.Errorf("mongo client couldn't connect with background context: %v", err)
// }
DB := client.Database("platypusNEST")
return DB, nil
{color:#c5c8c6}}
- is related to
-
GODRIVER-839 GoDoc for mongo.Client does not match API
- Closed