Last active
December 30, 2019 21:45
-
-
Save JNaeemGitonga/0b071d25c99c016e0cd3a805e527539c to your computer and use it in GitHub Desktop.
func connectToMongoDB() {...}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func connectToMongoDB() { | |
if client != nil { | |
return | |
} | |
var connectionError error | |
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) | |
client, connectionError = mongo.Connect(ctx, options.Client().ApplyURI(mongoURI)) | |
fmt.Printf("%+v", client) | |
collection = client.Database(dbName).Collection(col) // <--- since I'm only using one collection this can be global | |
defer cancel() | |
if connectionError != nil { | |
fmt.Printf("this is an eror %+v", connectionError) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment