-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-47023 Connection pools #505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
8685039
6bd4655
471a9e5
962a813
666aaa1
39c3245
24581a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"go.mongodb.org/mongo-driver/v2/mongo" | ||
"go.mongodb.org/mongo-driver/v2/mongo/options" | ||
) | ||
|
||
func main() { | ||
//start-connection-pool-uri | ||
// Connection string with connection pool options | ||
uri := "mongodb://localhost:27017/?maxPoolSize=50&minPoolSize=10&maxIdleTimeMS=30000" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of using a connection string over the client options? If we keep the clientOpts := options.Client().
ApplyURI("mongodb://localhost:27017").
SetMaxPoolSize(50).
SetMinPoolSize(10).
SetMaxConnIdleTime(30 * time.Second) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I based using the connection string off the existing FAQ in the Go docs. But I can use tabs here and show the connection string approach and the client options approach. Will rework! |
||
|
||
// Creates a new client and connect to the server | ||
client, err := mongo.Connect(options.Client().ApplyURI(uri)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
//end-connection-pool-uri | ||
|
||
defer func() { | ||
if err = client.Disconnect(context.TODO()); err != nil { | ||
log.Fatal(err) | ||
} | ||
}() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note for technical reviewer] Is this option still in use or is there a preferred option to this one? This was the option included in the existing FAQ.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prestonvasquez not sure if you saw this question. Was just curious because I know some drivers deprecated this option but I wasn't sure about the Go driver.