diff --git a/README.md b/README.md index 8e932cd7f7..e42143c96e 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ import ( ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() -client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017")) +client, err := mongo.Connect(options.Client().ApplyURI("mongodb://localhost:27017")) ``` Make sure to defer a call to `Disconnect` after instantiating your client: @@ -166,12 +166,12 @@ Compression can be enabled using the `compressors` parameter on the connection s ```go opts := options.Client().ApplyURI("mongodb://localhost:27017/?compressors=snappy,zlib,zstd") -client, _ := mongo.Connect(context.TODO(), opts) +client, _ := mongo.Connect(opts) ``` ```go opts := options.Client().SetCompressors([]string{"snappy", "zlib", "zstd"}) -client, _ := mongo.Connect(context.TODO(), opts) +client, _ := mongo.Connect(opts) ``` If compressors are set, the Go Driver negotiates with the server to select the first common compressor. For server configuration and defaults, refer to [`networkMessageCompressors`](https://www.mongodb.com/docs/manual/reference/program/mongod/#std-option-mongod.--networkMessageCompressors). diff --git a/benchmark/multi.go b/benchmark/multi.go index e003420718..103522ee6d 100644 --- a/benchmark/multi.go +++ b/benchmark/multi.go @@ -17,7 +17,7 @@ func MultiFindMany(ctx context.Context, tm TimerManager, iters int) error { ctx, cancel := context.WithCancel(ctx) defer cancel() - db, err := getClientDB(ctx) + db, err := getClientDB() if err != nil { return err } @@ -83,7 +83,7 @@ func multiInsertCase(ctx context.Context, tm TimerManager, iters int, data strin ctx, cancel := context.WithCancel(ctx) defer cancel() - db, err := getClientDB(ctx) + db, err := getClientDB() if err != nil { return err } diff --git a/benchmark/operation_test.go b/benchmark/operation_test.go index d53f75c994..3e555500e2 100644 --- a/benchmark/operation_test.go +++ b/benchmark/operation_test.go @@ -32,7 +32,7 @@ func BenchmarkClientWrite(b *testing.B) { } for _, bm := range benchmarks { b.Run(bm.name, func(b *testing.B) { - client, err := mongo.Connect(context.Background(), bm.opt) + client, err := mongo.Connect(bm.opt) if err != nil { b.Fatalf("error creating client: %v", err) } @@ -71,7 +71,7 @@ func BenchmarkClientBulkWrite(b *testing.B) { } for _, bm := range benchmarks { b.Run(bm.name, func(b *testing.B) { - client, err := mongo.Connect(context.Background(), bm.opt) + client, err := mongo.Connect(bm.opt) if err != nil { b.Fatalf("error creating client: %v", err) } @@ -115,7 +115,7 @@ func BenchmarkClientRead(b *testing.B) { } for _, bm := range benchmarks { b.Run(bm.name, func(b *testing.B) { - client, err := mongo.Connect(context.Background(), bm.opt) + client, err := mongo.Connect(bm.opt) if err != nil { b.Fatalf("error creating client: %v", err) } diff --git a/benchmark/single.go b/benchmark/single.go index d8366e34f6..2cd00bd0ae 100644 --- a/benchmark/single.go +++ b/benchmark/single.go @@ -24,12 +24,12 @@ const ( largeData = "large_doc.json" ) -func getClientDB(ctx context.Context) (*mongo.Database, error) { +func getClientDB() (*mongo.Database, error) { cs, err := integtest.GetConnString() if err != nil { return nil, err } - client, err := mongo.Connect(ctx, options.Client().ApplyURI(cs.String())) + client, err := mongo.Connect(options.Client().ApplyURI(cs.String())) if err != nil { return nil, err } @@ -42,7 +42,7 @@ func SingleRunCommand(ctx context.Context, tm TimerManager, iters int) error { ctx, cancel := context.WithCancel(ctx) defer cancel() - db, err := getClientDB(ctx) + db, err := getClientDB() if err != nil { return err } @@ -75,7 +75,7 @@ func SingleFindOneByID(ctx context.Context, tm TimerManager, iters int) error { ctx, cancel := context.WithCancel(ctx) defer cancel() - db, err := getClientDB(ctx) + db, err := getClientDB() if err != nil { return err } @@ -123,7 +123,7 @@ func singleInsertCase(ctx context.Context, tm TimerManager, iters int, data stri ctx, cancel := context.WithCancel(ctx) defer cancel() - db, err := getClientDB(ctx) + db, err := getClientDB() if err != nil { return err } diff --git a/cmd/testatlas/main.go b/cmd/testatlas/main.go index ae1b15fcbc..1bf2f8faff 100644 --- a/cmd/testatlas/main.go +++ b/cmd/testatlas/main.go @@ -51,7 +51,7 @@ func main() { } func runTest(ctx context.Context, clientOpts *options.ClientOptions) error { - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { return fmt.Errorf("Connect error: %w", err) } diff --git a/cmd/testaws/main.go b/cmd/testaws/main.go index ec4a1c91c3..4bdf50c340 100644 --- a/cmd/testaws/main.go +++ b/cmd/testaws/main.go @@ -21,7 +21,7 @@ func main() { uri := os.Getenv("MONGODB_URI") ctx := context.Background() - client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri)) + client, err := mongo.Connect(options.Client().ApplyURI(uri)) if err != nil { panic(fmt.Sprintf("Connect error: %v", err)) } diff --git a/cmd/testentauth/main.go b/cmd/testentauth/main.go index 9bcea33294..bcb2e6a427 100644 --- a/cmd/testentauth/main.go +++ b/cmd/testentauth/main.go @@ -22,7 +22,6 @@ func main() { compressor := os.Getenv("MONGO_GO_DRIVER_COMPRESSOR") client, err := mongo.Connect( - context.Background(), options.Client().ApplyURI(uri).SetCompressors([]string{compressor})) if err != nil { log.Fatalf("Error connecting client: %v", err) diff --git a/cmd/testkms/main.go b/cmd/testkms/main.go index bc8f6b6dfe..2151201d33 100644 --- a/cmd/testkms/main.go +++ b/cmd/testkms/main.go @@ -83,7 +83,7 @@ func main() { } cOpts := options.Client().ApplyURI(uri) - keyVaultClient, err := mongo.Connect(context.Background(), cOpts) + keyVaultClient, err := mongo.Connect(cOpts) if err != nil { panic(fmt.Sprintf("Connect error: %v", err)) } diff --git a/event/doc.go b/event/doc.go index 239340130f..9bade98cf7 100644 --- a/event/doc.go +++ b/event/doc.go @@ -21,7 +21,7 @@ // }, // } // clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetMonitor(cmdMonitor) -// client, err := mongo.Connect(context.Background(), clientOpts) +// client, err := mongo.Connect( clientOpts) // // Monitoring the connection pool requires specifying a PoolMonitor when constructing // a mongo.Client. The following code tracks the number of checked out connections: @@ -38,7 +38,7 @@ // }, // } // clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetPoolMonitor(poolMonitor) -// client, err := mongo.Connect(context.Background(), clientOpts) +// client, err := mongo.Connect( clientOpts) // // Monitoring server changes specifying a ServerMonitor object when constructing // a mongo.Client. Different functions can be set on the ServerMonitor to @@ -52,5 +52,5 @@ // } // } // clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetServerMonitor(svrMonitor) -// client, err := mongo.Connect(context.Background(), clientOpts) +// client, err := mongo.Connect( clientOpts) package event diff --git a/event/examples_test.go b/event/examples_test.go index 5041006568..7c151d2a9e 100644 --- a/event/examples_test.go +++ b/event/examples_test.go @@ -47,7 +47,7 @@ func ExampleCommandMonitor() { }, } clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetMonitor(cmdMonitor) - client, err := mongo.Connect(context.Background(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } diff --git a/examples/_logger/logrus/main.go b/examples/_logger/logrus/main.go index c75d72ccc2..7ef12c124c 100644 --- a/examples/_logger/logrus/main.go +++ b/examples/_logger/logrus/main.go @@ -39,7 +39,7 @@ func main() { ApplyURI("mongodb://localhost:27017"). SetLoggerOptions(loggerOptions) - client, err := mongo.Connect(context.TODO(), clientOptions) + client, err := mongo.Connect(clientOptions) if err != nil { log.Fatalf("error connecting to MongoDB: %v", err) } diff --git a/examples/_logger/zap/main.go b/examples/_logger/zap/main.go index ff061413f4..d7424e2e15 100644 --- a/examples/_logger/zap/main.go +++ b/examples/_logger/zap/main.go @@ -39,7 +39,7 @@ func main() { ApplyURI("mongodb://localhost:27017"). SetLoggerOptions(loggerOptions) - client, err := mongo.Connect(context.TODO(), clientOptions) + client, err := mongo.Connect(clientOptions) if err != nil { log.Fatalf("error connecting to MongoDB: %v", err) } diff --git a/examples/_logger/zerolog/main.go b/examples/_logger/zerolog/main.go index 58efe415b1..1e01f49437 100644 --- a/examples/_logger/zerolog/main.go +++ b/examples/_logger/zerolog/main.go @@ -36,7 +36,7 @@ func main() { ApplyURI("mongodb://localhost:27017"). SetLoggerOptions(loggerOptions) - client, err := mongo.Connect(context.TODO(), clientOptions) + client, err := mongo.Connect(clientOptions) if err != nil { log.Fatalf("error connecting to MongoDB: %v", err) } diff --git a/examples/documentation_examples/examples.go b/examples/documentation_examples/examples.go index 8da21a6209..eb0c4de066 100644 --- a/examples/documentation_examples/examples.go +++ b/examples/documentation_examples/examples.go @@ -1966,7 +1966,7 @@ func WithTransactionExample(ctx context.Context) error { uri := mtest.ClusterURI() clientOpts := options.Client().ApplyURI(uri) - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { return err } @@ -2781,7 +2781,7 @@ func StableAPIExample() { serverAPIOptions := options.ServerAPI(options.ServerAPIVersion1) clientOpts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPIOptions) - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { panic(err) } @@ -2803,7 +2803,7 @@ func StableAPIStrictExample() { serverAPIOptions := options.ServerAPI(options.ServerAPIVersion1).SetStrict(true) clientOpts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPIOptions) - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { panic(err) } @@ -2825,7 +2825,7 @@ func StableAPINonStrictExample() { serverAPIOptions := options.ServerAPI(options.ServerAPIVersion1).SetStrict(false) clientOpts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPIOptions) - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { panic(err) } @@ -2848,7 +2848,7 @@ func StableAPIDeprecationErrorsExample() { serverAPIOptions := options.ServerAPI(options.ServerAPIVersion1).SetDeprecationErrors(true) clientOpts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPIOptions) - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { panic(err) } @@ -2869,7 +2869,7 @@ func StableAPIStrictCountExample(t *testing.T) { serverAPIOptions := options.ServerAPI(options.ServerAPIVersion1).SetStrict(true) clientOpts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPIOptions) - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(t, err, "Connect error: %v", err) defer func() { _ = client.Disconnect(context.TODO()) }() diff --git a/examples/documentation_examples/examples_test.go b/examples/documentation_examples/examples_test.go index 141056f6da..429a9db58e 100644 --- a/examples/documentation_examples/examples_test.go +++ b/examples/documentation_examples/examples_test.go @@ -44,7 +44,7 @@ func TestDocumentationExamples(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(mtest.ClusterURI())) + client, err := mongo.Connect(options.Client().ApplyURI(mtest.ClusterURI())) assert.NoError(t, err) defer client.Disconnect(ctx) diff --git a/internal/test/compilecheck/main.go b/internal/test/compilecheck/main.go index 1678e64cde..cb35d6133d 100644 --- a/internal/test/compilecheck/main.go +++ b/internal/test/compilecheck/main.go @@ -7,7 +7,6 @@ package main import ( - "context" "fmt" "go.mongodb.org/mongo-driver/bson" @@ -16,6 +15,6 @@ import ( ) func main() { - _, _ = mongo.Connect(context.Background(), options.Client()) + _, _ = mongo.Connect(options.Client()) fmt.Println(bson.D{{Key: "key", Value: "value"}}) } diff --git a/mongo/client.go b/mongo/client.go index 0afbec29d8..fe6071cd75 100644 --- a/mongo/client.go +++ b/mongo/client.go @@ -102,12 +102,12 @@ type Client struct { // // The Client.Ping method can be used to verify that the deployment is successfully connected and the // Client was correctly configured. -func Connect(ctx context.Context, opts ...*options.ClientOptions) (*Client, error) { +func Connect(opts ...*options.ClientOptions) (*Client, error) { c, err := newClient(opts...) if err != nil { return nil, err } - err = c.connect(ctx) + err = c.connect() if err != nil { return nil, err } @@ -237,7 +237,7 @@ func newClient(opts ...*options.ClientOptions) (*Client, error) { // // Connect starts background goroutines to monitor the state of the deployment and does not do any I/O in the main // goroutine. The Client.Ping method can be used to verify that the connection was created successfully. -func (c *Client) connect(ctx context.Context) error { +func (c *Client) connect() error { if connector, ok := c.deployment.(driver.Connector); ok { err := connector.Connect() if err != nil { @@ -246,25 +246,25 @@ func (c *Client) connect(ctx context.Context) error { } if c.mongocryptdFLE != nil { - if err := c.mongocryptdFLE.connect(ctx); err != nil { + if err := c.mongocryptdFLE.connect(); err != nil { return err } } if c.internalClientFLE != nil { - if err := c.internalClientFLE.connect(ctx); err != nil { + if err := c.internalClientFLE.connect(); err != nil { return err } } if c.keyVaultClientFLE != nil && c.keyVaultClientFLE != c.internalClientFLE && c.keyVaultClientFLE != c { - if err := c.keyVaultClientFLE.connect(ctx); err != nil { + if err := c.keyVaultClientFLE.connect(); err != nil { return err } } if c.metadataClientFLE != nil && c.metadataClientFLE != c.internalClientFLE && c.metadataClientFLE != c { - if err := c.metadataClientFLE.connect(ctx); err != nil { + if err := c.metadataClientFLE.connect(); err != nil { return err } } diff --git a/mongo/client_examples_test.go b/mongo/client_examples_test.go index 4123e8e0e4..e6654ba84d 100644 --- a/mongo/client_examples_test.go +++ b/mongo/client_examples_test.go @@ -21,7 +21,6 @@ func ExampleClient() { // Create a Client and execute a ListDatabases operation. client, err := mongo.Connect( - context.TODO(), options.Client().ApplyURI("mongodb://localhost:27017")) if err != nil { log.Fatal(err) @@ -45,7 +44,7 @@ func ExampleConnect_ping() { // server is running. clientOpts := options.Client().ApplyURI("mongodb://localhost:27017") - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } @@ -74,7 +73,7 @@ func ExampleConnect_replicaSet() { clientOpts := options.Client().ApplyURI( "mongodb://localhost:27017,localhost:27018/?replicaSet=replset") - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } @@ -88,7 +87,7 @@ func ExampleConnect_sharded() { clientOpts := options.Client().ApplyURI( "mongodb://localhost:27017,localhost:27018") - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } @@ -106,7 +105,7 @@ func ExampleConnect_sRV() { // requires driver version 1.1.0 or higher. clientOpts := options.Client().ApplyURI("mongodb+srv://mongodb.example.com") - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } @@ -120,7 +119,7 @@ func ExampleConnect_direct() { clientOpts := options.Client().ApplyURI( "mongodb://localhost:27017/?connect=direct") - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } @@ -143,7 +142,7 @@ func ExampleConnect_sCRAM() { } clientOpts := options.Client().ApplyURI("mongodb://localhost:27017"). SetAuth(credential) - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } @@ -179,7 +178,7 @@ func ExampleConnect_x509() { } clientOpts := options.Client().ApplyURI(uri).SetAuth(credential) - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } @@ -204,7 +203,7 @@ func ExampleConnect_pLAIN() { clientOpts := options.Client().ApplyURI("mongodb://localhost:27017"). SetAuth(credential) - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } @@ -239,7 +238,7 @@ func ExampleConnect_kerberos() { uri := "mongo-server.example.com:27017" clientOpts := options.Client().ApplyURI(uri).SetAuth(credential) - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { log.Fatal(err) } @@ -289,7 +288,6 @@ func ExampleConnect_aWS() { Password: secretAccessKey, } awsIAMClient, err := mongo.Connect( - context.TODO(), options.Client().SetAuth(awsCredential)) if err != nil { panic(err) @@ -311,7 +309,6 @@ func ExampleConnect_aWS() { }, } assumeRoleClient, err := mongo.Connect( - context.TODO(), options.Client().SetAuth(assumeRoleCredential)) if err != nil { panic(err) @@ -333,7 +330,6 @@ func ExampleConnect_aWS() { AuthMechanism: "MONGODB-AWS", } envVariablesClient, err := mongo.Connect( - context.TODO(), options.Client().SetAuth(envVariablesCredential)) if err != nil { panic(err) @@ -350,9 +346,7 @@ func ExampleConnect_aWS() { ecCredential := options.Credential{ AuthMechanism: "MONGODB-AWS", } - ecClient, err := mongo.Connect( - context.TODO(), - options.Client().SetAuth(ecCredential)) + ecClient, err := mongo.Connect(options.Client().SetAuth(ecCredential)) if err != nil { panic(err) } @@ -382,7 +376,6 @@ func ExampleConnect_stableAPI() { // is a constant equal to "1". serverAPI := options.ServerAPI(options.ServerAPIVersion1) serverAPIClient, err := mongo.Connect( - context.TODO(), options.Client().SetServerAPIOptions(serverAPI)) if err != nil { panic(err) @@ -397,7 +390,6 @@ func ExampleConnect_stableAPI() { serverAPIStrict := options.ServerAPI(options.ServerAPIVersion1). SetStrict(true) serverAPIStrictClient, err := mongo.Connect( - context.TODO(), options.Client().SetServerAPIOptions(serverAPIStrict)) if err != nil { panic(err) @@ -416,7 +408,6 @@ func ExampleConnect_stableAPI() { serverAPIDeprecation := options.ServerAPI(options.ServerAPIVersion1). SetDeprecationErrors(true) serverAPIDeprecationClient, err := mongo.Connect( - context.TODO(), options.Client().SetServerAPIOptions(serverAPIDeprecation)) if err != nil { panic(err) @@ -442,7 +433,7 @@ func ExampleConnect_bSONOptions() { ApplyURI("mongodb://localhost:27017"). SetBSONOptions(bsonOpts) - client, err := mongo.Connect(context.TODO(), clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { panic(err) } diff --git a/mongo/client_side_encryption_examples_test.go b/mongo/client_side_encryption_examples_test.go index 70243c4cc9..d2e6449fe4 100644 --- a/mongo/client_side_encryption_examples_test.go +++ b/mongo/client_side_encryption_examples_test.go @@ -39,7 +39,7 @@ func Example_clientSideEncryption() { clientOpts := options.Client(). ApplyURI(uri). SetAutoEncryptionOptions(autoEncryptionOpts) - client, err := Connect(context.TODO(), clientOpts) + client, err := Connect(clientOpts) if err != nil { log.Fatalf("Connect error: %v", err) } @@ -78,9 +78,7 @@ func Example_clientSideEncryptionCreateKey() { clientEncryptionOpts := options.ClientEncryption(). SetKeyVaultNamespace(keyVaultNamespace). SetKmsProviders(kmsProviders) - keyVaultClient, err := Connect( - context.TODO(), - options.Client().ApplyURI(uri)) + keyVaultClient, err := Connect(options.Client().ApplyURI(uri)) if err != nil { log.Fatalf("Connect error for keyVaultClient: %v", err) } @@ -142,7 +140,7 @@ func Example_clientSideEncryptionCreateKey() { clientOptions := options.Client(). ApplyURI(uri). SetAutoEncryptionOptions(autoEncryptionOpts) - client, err := Connect(context.TODO(), clientOptions) + client, err := Connect(clientOptions) if err != nil { log.Fatalf("Connect error for encrypted client: %v", err) } @@ -169,9 +167,8 @@ func Example_explictEncryption() { keyVaultNamespace := keyVaultDBName + "." + keyVaultCollName // The Client used to read/write application data. - client, err := Connect( - context.TODO(), - options.Client().ApplyURI("mongodb://localhost:27017")) + opts := options.Client().ApplyURI("mongodb://localhost:27017") + client, err := Connect(opts) if err != nil { panic(err) } @@ -294,7 +291,7 @@ func Example_explictEncryptionWithAutomaticDecryption() { clientOpts := options.Client(). ApplyURI("mongodb://localhost:27017"). SetAutoEncryptionOptions(autoEncryptionOpts) - client, err := Connect(context.TODO(), clientOpts) + client, err := Connect(clientOpts) if err != nil { panic(err) } diff --git a/mongo/client_test.go b/mongo/client_test.go index e90215108c..6046b5abc2 100644 --- a/mongo/client_test.go +++ b/mongo/client_test.go @@ -357,7 +357,7 @@ func TestClient(t *testing.T) { clientOpts := options.Client().ApplyURI(cs.Original).SetReadPreference(readpref.Primary()). SetWriteConcern(writeconcern.Majority()).SetMonitor(cmdMonitor) integtest.AddTestServerAPIVersion(clientOpts) - client, err := Connect(bgCtx, clientOpts) + client, err := Connect(clientOpts) assert.Nil(t, err, "Connect error: %v", err) defer func() { _ = client.Disconnect(bgCtx) diff --git a/mongo/crud_examples_test.go b/mongo/crud_examples_test.go index e76d279139..f4b64a98ad 100644 --- a/mongo/crud_examples_test.go +++ b/mongo/crud_examples_test.go @@ -1080,7 +1080,7 @@ func ExampleCollection_Find_primitiveRegex() { clientOptions := options.Client().ApplyURI("mongodb://localhost:27017") // Connect to a mongodb server. - client, err := mongo.Connect(ctx, clientOptions) + client, err := mongo.Connect(clientOptions) if err != nil { panic(err) } @@ -1121,7 +1121,7 @@ func ExampleCollection_Find_regex() { clientOptions := options.Client().ApplyURI("mongodb://localhost:27017") // Connect to a mongodb server. - client, err := mongo.Connect(ctx, clientOptions) + client, err := mongo.Connect(clientOptions) if err != nil { panic(err) } diff --git a/mongo/database_test.go b/mongo/database_test.go index 745f533b73..fa2c603d9d 100644 --- a/mongo/database_test.go +++ b/mongo/database_test.go @@ -97,7 +97,7 @@ func TestDatabase(t *testing.T) { }) t.Run("TransientTransactionError label", func(t *testing.T) { client := setupClient(options.Client().ApplyURI("mongodb://nonexistent").SetServerSelectionTimeout(3 * time.Second)) - err := client.connect(bgCtx) + err := client.connect() defer func() { _ = client.Disconnect(bgCtx) }() assert.Nil(t, err, "expected nil, got %v", err) diff --git a/mongo/doc.go b/mongo/doc.go index e0a5d66ac2..8a037c7ed6 100644 --- a/mongo/doc.go +++ b/mongo/doc.go @@ -13,7 +13,7 @@ // // ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) // defer cancel() -// client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://foo:bar@localhost:27017")) +// client, err := mongo.Connect( options.Client().ApplyURI("mongodb://foo:bar@localhost:27017")) // if err != nil { return err } // // This will create a new client and start monitoring the MongoDB server on localhost. diff --git a/mongo/gridfs/bucket_test.go b/mongo/gridfs/bucket_test.go index 0bff0ed871..b0a50520fa 100644 --- a/mongo/gridfs/bucket_test.go +++ b/mongo/gridfs/bucket_test.go @@ -38,7 +38,7 @@ func TestBucket_openDownloadStream(t *testing.T) { cs := integtest.ConnString(t) clientOpts := options.Client().ApplyURI(cs.Original) - client, err := mongo.Connect(context.Background(), clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(t, err, "Connect error: %v", err) db := client.Database("bucket") diff --git a/mongo/gridfs/gridfs_test.go b/mongo/gridfs/gridfs_test.go index ea9d39efe4..b3af58518c 100644 --- a/mongo/gridfs/gridfs_test.go +++ b/mongo/gridfs/gridfs_test.go @@ -49,7 +49,7 @@ func TestGridFS(t *testing.T) { // will discover the other hosts during SDAM checks. SetHosts(cs.Hosts[:1]) - client, err := mongo.Connect(context.Background(), clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(t, err, "Connect error: %v", err) db := client.Database("gridfs") defer func() { diff --git a/mongo/integration/clam_prose_test.go b/mongo/integration/clam_prose_test.go index 3b0ad2cde1..52b2b85f1d 100644 --- a/mongo/integration/clam_prose_test.go +++ b/mongo/integration/clam_prose_test.go @@ -321,7 +321,7 @@ func TestCommandLoggingAndMonitoringProse(t *testing.T) { integtest.AddTestServerAPIVersion(clientOpts) - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(mt, err, "Connect error in setup: %v", err) coll := mt.CreateCollection(mtest.Collection{ @@ -379,7 +379,7 @@ func TestCommandLoggingAndMonitoringProse(t *testing.T) { integtest.AddTestServerAPIVersion(clientOpts) - client, err := mongo.Connect(context.Background(), clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(mt, err, "Connect error: %v", err) coll := mt.CreateCollection(mtest.Collection{ diff --git a/mongo/integration/client_options_test.go b/mongo/integration/client_options_test.go index 43703d5e33..4287842149 100644 --- a/mongo/integration/client_options_test.go +++ b/mongo/integration/client_options_test.go @@ -24,7 +24,7 @@ func TestClientOptions_CustomDialer(t *testing.T) { cs := integtest.ConnString(t) opts := options.Client().ApplyURI(cs.String()).SetDialer(td) integtest.AddTestServerAPIVersion(opts) - client, err := mongo.Connect(context.Background(), opts) + client, err := mongo.Connect(opts) require.NoError(t, err) _, err = client.ListDatabases(context.Background(), bson.D{}) require.NoError(t, err) diff --git a/mongo/integration/client_side_encryption_prose_test.go b/mongo/integration/client_side_encryption_prose_test.go index 22dde7c896..46fceaab2c 100644 --- a/mongo/integration/client_side_encryption_prose_test.go +++ b/mongo/integration/client_side_encryption_prose_test.go @@ -1153,7 +1153,7 @@ func TestClientSideEncryptionProse(t *testing.T) { mcryptOpts := options.Client().ApplyURI("mongodb://localhost:27021"). SetServerSelectionTimeout(1 * time.Second) integtest.AddTestServerAPIVersion(mcryptOpts) - mcryptClient, err := mongo.Connect(context.Background(), mcryptOpts) + mcryptClient, err := mongo.Connect(mcryptOpts) assert.Nil(mt, err, "mongocryptd Connect error: %v", err) err = mcryptClient.Database("admin").RunCommand(context.Background(), bson.D{{handshake.LegacyHelloLowercase, 1}}).Err() @@ -1364,7 +1364,7 @@ func TestClientSideEncryptionProse(t *testing.T) { SetAutoEncryptionOptions(aeOpts) integtest.AddTestServerAPIVersion(ceOpts) - clientEncrypted, err := mongo.Connect(context.Background(), ceOpts) + clientEncrypted, err := mongo.Connect(ceOpts) assert.Nil(mt, err, "Connect error: %v", err) defer clientEncrypted.Disconnect(context.Background()) @@ -1682,7 +1682,7 @@ func TestClientSideEncryptionProse(t *testing.T) { assert.Nil(mt, err, "error on CreateCollection: %v", err) err = mt.Client.Database("keyvault").Collection("datakeys").Drop(context.Background()) assert.Nil(mt, err, "error on Drop: %v", err) - keyVaultClient, err := mongo.Connect(context.Background(), options.Client().ApplyURI(mtest.ClusterURI())) + keyVaultClient, err := mongo.Connect(options.Client().ApplyURI(mtest.ClusterURI())) assert.Nil(mt, err, "error on Connect: %v", err) datakeysColl := keyVaultClient.Database("keyvault").Collection("datakeys", options.Collection().SetWriteConcern(mtest.MajorityWc)) _, err = datakeysColl.InsertOne(context.Background(), key1Document) @@ -1700,7 +1700,7 @@ func TestClientSideEncryptionProse(t *testing.T) { SetKmsProviders(fullKmsProvidersMap). SetBypassQueryAnalysis(true) co := options.Client().SetAutoEncryptionOptions(aeo).ApplyURI(mtest.ClusterURI()) - encryptedClient, err := mongo.Connect(context.Background(), co) + encryptedClient, err := mongo.Connect(co) assert.Nil(mt, err, "error on Connect: %v", err) return encryptedClient, clientEncryption } @@ -2036,7 +2036,7 @@ func TestClientSideEncryptionProse(t *testing.T) { var keyVaultClient *mongo.Client { co := options.Client().ApplyURI(mtest.ClusterURI()) - keyVaultClient, err = mongo.Connect(context.Background(), co) + keyVaultClient, err = mongo.Connect(co) defer keyVaultClient.Disconnect(context.Background()) integtest.AddTestServerAPIVersion(co) assert.Nil(mt, err, "error on Connect: %v", err) @@ -2078,7 +2078,7 @@ func TestClientSideEncryptionProse(t *testing.T) { var keyVaultClient *mongo.Client { co := options.Client().ApplyURI(mtest.ClusterURI()) - keyVaultClient, err = mongo.Connect(context.Background(), co) + keyVaultClient, err = mongo.Connect(co) defer keyVaultClient.Disconnect(context.Background()) integtest.AddTestServerAPIVersion(co) assert.Nil(mt, err, "error on Connect: %v", err) @@ -2128,7 +2128,7 @@ func TestClientSideEncryptionProse(t *testing.T) { var keyVaultClient *mongo.Client { co := options.Client().ApplyURI(mtest.ClusterURI()) - keyVaultClient, err = mongo.Connect(context.Background(), co) + keyVaultClient, err = mongo.Connect(co) defer keyVaultClient.Disconnect(context.Background()) integtest.AddTestServerAPIVersion(co) assert.Nil(mt, err, "error on Connect: %v", err) @@ -2271,7 +2271,7 @@ func TestClientSideEncryptionProse(t *testing.T) { SetExtraOptions(mongocryptdSpawnArgs) cliOpts := options.Client().ApplyURI(mtest.ClusterURI()).SetAutoEncryptionOptions(aeo) integtest.AddTestServerAPIVersion(cliOpts) - encClient, err := mongo.Connect(context.Background(), cliOpts) + encClient, err := mongo.Connect(cliOpts) assert.Nil(mt, err, "Connect error: %v", err) defer func() { err = encClient.Disconnect(context.Background()) @@ -2291,7 +2291,7 @@ func TestClientSideEncryptionProse(t *testing.T) { mt.RunOpts("21. automatic data encryption keys", qeRunOpts, func(mt *mtest.T) { setup := func() (*mongo.Client, *mongo.ClientEncryption, error) { opts := options.Client().ApplyURI(mtest.ClusterURI()) - client, err := mongo.Connect(context.Background(), opts) + client, err := mongo.Connect(opts) if err != nil { return nil, nil, err } @@ -2603,7 +2603,7 @@ func TestClientSideEncryptionProse(t *testing.T) { assert.Nil(mt, err, "error on CreateCollection: %v", err) err = mt.Client.Database("keyvault").Collection("datakeys").Drop(context.Background()) assert.Nil(mt, err, "error on Drop: %v", err) - keyVaultClient, err := mongo.Connect(context.Background(), options.Client().ApplyURI(mtest.ClusterURI())) + keyVaultClient, err := mongo.Connect(options.Client().ApplyURI(mtest.ClusterURI())) assert.Nil(mt, err, "error on Connect: %v", err) datakeysColl := keyVaultClient.Database("keyvault").Collection("datakeys", options.Collection().SetWriteConcern(mtest.MajorityWc)) _, err = datakeysColl.InsertOne(context.Background(), key1Document) @@ -2621,7 +2621,7 @@ func TestClientSideEncryptionProse(t *testing.T) { SetKmsProviders(fullKmsProvidersMap). SetBypassQueryAnalysis(true) co := options.Client().SetAutoEncryptionOptions(aeo).ApplyURI(mtest.ClusterURI()) - encryptedClient, err := mongo.Connect(context.Background(), co) + encryptedClient, err := mongo.Connect(co) assert.Nil(mt, err, "error on Connect: %v", err) // Insert 0, 6, 30, and 200. @@ -2956,12 +2956,12 @@ func setup(mt *mtest.T, aeo *options.AutoEncryptionOptions, kvClientOpts *option opts := options.Client().ApplyURI(mtest.ClusterURI()).SetWriteConcern(mtest.MajorityWc). SetReadPreference(mtest.PrimaryRp).SetAutoEncryptionOptions(aeo).SetMonitor(cseMonitor) integtest.AddTestServerAPIVersion(opts) - cpt.cseClient, err = mongo.Connect(context.Background(), opts) + cpt.cseClient, err = mongo.Connect(opts) assert.Nil(mt, err, "Connect error for encrypted client: %v", err) cpt.cseColl = cpt.cseClient.Database("db").Collection("coll") } if ceo != nil { - cpt.kvClient, err = mongo.Connect(context.Background(), kvClientOpts) + cpt.kvClient, err = mongo.Connect(kvClientOpts) assert.Nil(mt, err, "Connect error for ClientEncryption key vault client: %v", err) cpt.clientEnc, err = mongo.NewClientEncryption(cpt.kvClient, ceo) assert.Nil(mt, err, "NewClientEncryption error: %v", err) @@ -3029,7 +3029,7 @@ func newDeadlockTest(mt *mtest.T) *deadlockTest { clientTestOpts := options.Client().ApplyURI(mtest.ClusterURI()).SetWriteConcern(mtest.MajorityWc) integtest.AddTestServerAPIVersion(clientTestOpts) - if d.clientTest, err = mongo.Connect(context.Background(), clientTestOpts); err != nil { + if d.clientTest, err = mongo.Connect(clientTestOpts); err != nil { mt.Fatalf("Connect error: %v", err) } diff --git a/mongo/integration/client_side_encryption_test.go b/mongo/integration/client_side_encryption_test.go index 928c3d12aa..5851080d32 100644 --- a/mongo/integration/client_side_encryption_test.go +++ b/mongo/integration/client_side_encryption_test.go @@ -43,7 +43,7 @@ func createDataKeyAndEncrypt(mt *mtest.T, keyName string) primitive.Binary { "local": {"key": localMasterKey}, } - kvClient, err := mongo.Connect(context.Background(), kvClientOpts) + kvClient, err := mongo.Connect(kvClientOpts) defer kvClient.Disconnect(context.Background()) assert.Nil(mt, err, "Connect error: %v", err) @@ -135,7 +135,7 @@ func TestClientSideEncryptionWithExplicitSessions(t *testing.T) { integtest.AddTestServerAPIVersion(clientOpts) - client, err := mongo.Connect(context.Background(), clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(mt, err, "Connect error: %v", err) defer client.Disconnect(context.Background()) @@ -197,7 +197,7 @@ func TestClientSideEncryptionWithExplicitSessions(t *testing.T) { integtest.AddTestServerAPIVersion(clientOpts) - client, err := mongo.Connect(context.Background(), clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(mt, err, "Connect error: %v", err) defer client.Disconnect(context.Background()) @@ -361,7 +361,7 @@ func TestClientSideEncryptionCustomCrypt(t *testing.T) { clientOpts.Crypt = cc integtest.AddTestServerAPIVersion(clientOpts) - client, err := mongo.Connect(context.Background(), clientOpts) + client, err := mongo.Connect(clientOpts) defer client.Disconnect(context.Background()) assert.Nil(mt, err, "Connect error: %v", err) @@ -506,7 +506,7 @@ func TestFLE2DocsExample(t *testing.T) { { cOpts := options.Client().ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cOpts) - keyVaultClient, err := mongo.Connect(context.Background(), cOpts) + keyVaultClient, err := mongo.Connect(cOpts) assert.Nil(mt, err, "error in Connect: %v", err) defer keyVaultClient.Disconnect(context.Background()) ceOpts := options.ClientEncryption().SetKmsProviders(kmsProvidersMap).SetKeyVaultNamespace("keyvault.datakeys") @@ -549,7 +549,7 @@ func TestFLE2DocsExample(t *testing.T) { integtest.AddTestServerAPIVersion(cOpts) aeOpts := options.AutoEncryption().SetKmsProviders(kmsProvidersMap).SetKeyVaultNamespace("keyvault.datakeys").SetEncryptedFieldsMap(encryptedFieldsMap).SetExtraOptions(getCryptSharedLibExtraOptions()) cOpts.SetAutoEncryptionOptions(aeOpts) - encryptedClient, err := mongo.Connect(context.Background(), cOpts) + encryptedClient, err := mongo.Connect(cOpts) defer encryptedClient.Disconnect(context.Background()) assert.Nil(mt, err, "error in Connect: %v", err) // Create the FLE 2 collection docsExample.encrypted. @@ -653,7 +653,7 @@ func TestFLE2CreateCollectionWithAutoEncryption(t *testing.T) { integtest.AddTestServerAPIVersion(cOpts) var err error - encryptedClient, err = mongo.Connect(context.Background(), cOpts) + encryptedClient, err = mongo.Connect(cOpts) defer encryptedClient.Disconnect(context.Background()) assert.Nil(mt, err, "error in Connect: %v", err) } diff --git a/mongo/integration/client_test.go b/mongo/integration/client_test.go index dafea690d0..c8ba161644 100644 --- a/mongo/integration/client_test.go +++ b/mongo/integration/client_test.go @@ -181,7 +181,7 @@ func TestClient(t *testing.T) { ) authClientOpts := options.Client().ApplyURI(cs) integtest.AddTestServerAPIVersion(authClientOpts) - authClient, err := mongo.Connect(context.Background(), authClientOpts) + authClient, err := mongo.Connect(authClientOpts) assert.Nil(mt, err, "authClient Connect error: %v", err) defer func() { _ = authClient.Disconnect(context.Background()) }() @@ -326,7 +326,7 @@ func TestClient(t *testing.T) { SetServerSelectionTimeout(100 * time.Millisecond).SetHosts([]string{"invalid:123"}). SetConnectTimeout(500 * time.Millisecond).SetSocketTimeout(500 * time.Millisecond) integtest.AddTestServerAPIVersion(invalidClientOpts) - client, err := mongo.Connect(context.Background(), invalidClientOpts) + client, err := mongo.Connect(invalidClientOpts) assert.Nil(mt, err, "Connect error: %v", err) err = client.Ping(context.Background(), readpref.Primary()) assert.NotNil(mt, err, "expected error for pinging invalid host, got nil") diff --git a/mongo/integration/crud_helpers_test.go b/mongo/integration/crud_helpers_test.go index c6a06e338e..5c5cc8c609 100644 --- a/mongo/integration/crud_helpers_test.go +++ b/mongo/integration/crud_helpers_test.go @@ -124,7 +124,7 @@ func runCommandOnAllServers(commandFn func(client *mongo.Client) error) error { integtest.AddTestServerAPIVersion(opts) if mtest.ClusterTopologyKind() != mtest.Sharded { - client, err := mongo.Connect(context.Background(), opts) + client, err := mongo.Connect(opts) if err != nil { return fmt.Errorf("error creating replica set client: %v", err) } @@ -134,7 +134,7 @@ func runCommandOnAllServers(commandFn func(client *mongo.Client) error) error { } for _, host := range opts.Hosts { - shardClient, err := mongo.Connect(context.Background(), opts.SetHosts([]string{host})) + shardClient, err := mongo.Connect(opts.SetHosts([]string{host})) if err != nil { return fmt.Errorf("error creating client for mongos %v: %v", host, err) } @@ -1386,7 +1386,7 @@ func executeAdminCommand(mt *mtest.T, op *operation) { // Per the streamable hello test format description, a separate client must be used to execute this operation. clientOpts := options.Client().ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(clientOpts) - client, err := mongo.Connect(context.Background(), clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(mt, err, "Connect error: %v", err) defer func() { _ = client.Disconnect(context.Background()) diff --git a/mongo/integration/csot_cse_prose_test.go b/mongo/integration/csot_cse_prose_test.go index e3b30f5c3c..f0102e70f2 100644 --- a/mongo/integration/csot_cse_prose_test.go +++ b/mongo/integration/csot_cse_prose_test.go @@ -47,7 +47,7 @@ func TestCSOTClientSideEncryptionProse(t *testing.T) { SetExtraOptions(mongocryptdSpawnArgs) cliOpts := options.Client().ApplyURI(mtest.ClusterURI()).SetAutoEncryptionOptions(aeo) integtest.AddTestServerAPIVersion(cliOpts) - encClient, err := mongo.Connect(context.Background(), cliOpts) + encClient, err := mongo.Connect(cliOpts) assert.Nil(mt, err, "Connect error: %v", err) defer func() { err = encClient.Disconnect(context.Background()) @@ -70,7 +70,7 @@ func TestCSOTClientSideEncryptionProse(t *testing.T) { mcryptOpts := options.Client().SetMonitor(mcryptMonitor). ApplyURI("mongodb://localhost:23000/?timeoutMS=1000") integtest.AddTestServerAPIVersion(mcryptOpts) - mcryptClient, err := mongo.Connect(context.Background(), mcryptOpts) + mcryptClient, err := mongo.Connect(mcryptOpts) assert.Nil(mt, err, "mongocryptd Connect error: %v", err) defer func() { err = mcryptClient.Disconnect(context.Background()) diff --git a/mongo/integration/csot_prose_test.go b/mongo/integration/csot_prose_test.go index 4f9f112b3f..7d0d387f52 100644 --- a/mongo/integration/csot_prose_test.go +++ b/mongo/integration/csot_prose_test.go @@ -57,7 +57,7 @@ func TestCSOTProse(t *testing.T) { SetMonitor(cm). ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) - cli, err := mongo.Connect(context.Background(), cliOptions) + cli, err := mongo.Connect(cliOptions) assert.Nil(mt, err, "Connect error: %v", err) // Insert 50 1MB documents (OP_MSG payloads can only fit 48MB in one batch). diff --git a/mongo/integration/errors_test.go b/mongo/integration/errors_test.go index ad2da491aa..7e976b0ce5 100644 --- a/mongo/integration/errors_test.go +++ b/mongo/integration/errors_test.go @@ -75,7 +75,7 @@ func TestErrors(t *testing.T) { clientOpts := options.Client().ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(clientOpts) - client, err := mongo.Connect(context.Background(), clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(mt, err, "Connect error: %v", err) defer func() { _ = client.Disconnect(context.Background()) }() diff --git a/mongo/integration/initial_dns_seedlist_discovery_test.go b/mongo/integration/initial_dns_seedlist_discovery_test.go index 92a20a721a..c17ee1e712 100644 --- a/mongo/integration/initial_dns_seedlist_discovery_test.go +++ b/mongo/integration/initial_dns_seedlist_discovery_test.go @@ -76,7 +76,7 @@ func runSeedlistDiscoveryDirectory(mt *mtest.T, subdirectory string) { func runSeedlistDiscoveryPingTest(mt *mtest.T, clientOpts *options.ClientOptions) { ctx := context.Background() - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) assert.Nil(mt, err, "Connect error: %v", err) defer func() { _ = client.Disconnect(ctx) }() diff --git a/mongo/integration/mtest/mongotest.go b/mongo/integration/mtest/mongotest.go index faf99e1259..d58a1dd469 100644 --- a/mongo/integration/mtest/mongotest.go +++ b/mongo/integration/mtest/mongotest.go @@ -685,13 +685,13 @@ func (t *T) createTestClient() { // pin to first mongos pinnedHostList := []string{testContext.connString.Hosts[0]} uriOpts := options.Client().ApplyURI(testContext.connString.Original).SetHosts(pinnedHostList) - t.Client, err = mongo.Connect(context.Background(), uriOpts, clientOpts) + t.Client, err = mongo.Connect(uriOpts, clientOpts) case Mock: // clear pool monitor to avoid configuration error clientOpts.PoolMonitor = nil t.mockDeployment = newMockDeployment() clientOpts.Deployment = t.mockDeployment - t.Client, err = mongo.Connect(context.Background(), clientOpts) + t.Client, err = mongo.Connect(clientOpts) case Proxy: t.proxyDialer = newProxyDialer() clientOpts.SetDialer(t.proxyDialer) @@ -709,7 +709,7 @@ func (t *T) createTestClient() { } // Pass in uriOpts first so clientOpts wins if there are any conflicting settings. - t.Client, err = mongo.Connect(context.Background(), uriOpts, clientOpts) + t.Client, err = mongo.Connect(uriOpts, clientOpts) } if err != nil { t.Fatalf("error creating client: %v", err) diff --git a/mongo/integration/mtest/setup.go b/mongo/integration/mtest/setup.go index 0c0ab21dbe..1096ba474d 100644 --- a/mongo/integration/mtest/setup.go +++ b/mongo/integration/mtest/setup.go @@ -65,7 +65,7 @@ func setupClient(opts *options.ClientOptions) (*mongo.Client, error) { } // for sharded clusters, pin to one host. Due to how the cache is implemented on 4.0 and 4.2, behavior // can be inconsistent when multiple mongoses are used - return mongo.Connect(context.Background(), opts.SetWriteConcern(wcMajority).SetHosts(opts.Hosts[:1])) + return mongo.Connect(opts.SetWriteConcern(wcMajority).SetHosts(opts.Hosts[:1])) } // Setup initializes the current testing context. diff --git a/mongo/integration/sessions_mongocryptd_prose_test.go b/mongo/integration/sessions_mongocryptd_prose_test.go index fd516445df..891d08d81c 100644 --- a/mongo/integration/sessions_mongocryptd_prose_test.go +++ b/mongo/integration/sessions_mongocryptd_prose_test.go @@ -100,9 +100,7 @@ func newTestSessionMongocryptdProseClient(mt *mtest.T) *mongo.Client { ApplyURI(uri.String()). SetMonitor(cmdMonitor) - ctx := context.Background() - - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) require.NoError(mt, err, "could not connect to mongocryptd: %v", err) return client diff --git a/mongo/integration/unified/admin_helpers.go b/mongo/integration/unified/admin_helpers.go index 4dcabb9f85..ba8eac8d7d 100644 --- a/mongo/integration/unified/admin_helpers.go +++ b/mongo/integration/unified/admin_helpers.go @@ -86,7 +86,7 @@ func runCommandOnHost(ctx context.Context, host string, commandFn func(context.C SetHosts([]string{host}) integtest.AddTestServerAPIVersion(clientOpts) - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { return fmt.Errorf("error creating client to host %q: %v", host, err) } diff --git a/mongo/integration/unified/client_entity.go b/mongo/integration/unified/client_entity.go index 66e2e55987..38ed4ed4da 100644 --- a/mongo/integration/unified/client_entity.go +++ b/mongo/integration/unified/client_entity.go @@ -189,7 +189,7 @@ func newClientEntity(ctx context.Context, em *EntityMap, entityOptions *entityOp entity.ignoredCommands[cmd] = struct{}{} } - client, err := mongo.Connect(ctx, clientOpts) + client, err := mongo.Connect(clientOpts) if err != nil { return nil, fmt.Errorf("error creating mongo.Client: %w", err) } diff --git a/mongo/integration/unified_spec_test.go b/mongo/integration/unified_spec_test.go index 4da42e6a68..63563e98d5 100644 --- a/mongo/integration/unified_spec_test.go +++ b/mongo/integration/unified_spec_test.go @@ -467,7 +467,7 @@ func executeTestRunnerOperation(mt *mtest.T, testCase *testCase, op *operation, targetHost := clientSession.PinnedServer.Addr.String() opts := options.Client().ApplyURI(mtest.ClusterURI()).SetHosts([]string{targetHost}) integtest.AddTestServerAPIVersion(opts) - client, err := mongo.Connect(context.Background(), opts) + client, err := mongo.Connect(opts) if err != nil { return fmt.Errorf("Connect error for targeted client: %w", err) } diff --git a/mongo/mongocryptd.go b/mongo/mongocryptd.go index 7af7f3a8f0..efb283e208 100644 --- a/mongo/mongocryptd.go +++ b/mongo/mongocryptd.go @@ -113,8 +113,8 @@ func (mc *mongocryptdClient) markCommand(ctx context.Context, dbName string, cmd } // connect connects the underlying Client instance. This must be called before performing any mark operations. -func (mc *mongocryptdClient) connect(ctx context.Context) error { - return mc.client.connect(ctx) +func (mc *mongocryptdClient) connect() error { + return mc.client.connect() } // disconnect disconnects the underlying Client instance. This should be called after all operations have completed. diff --git a/mongo/ocsp_test.go b/mongo/ocsp_test.go index 55cd4e1d9b..d97706855f 100644 --- a/mongo/ocsp_test.go +++ b/mongo/ocsp_test.go @@ -32,7 +32,7 @@ func TestOCSP(t *testing.T) { t.Run("tls", func(t *testing.T) { clientOpts := createOCSPClientOptions(cs.Original) - client, err := Connect(bgCtx, clientOpts) + client, err := Connect(clientOpts) assert.Nil(t, err, "Connect error: %v", err) defer func() { _ = client.Disconnect(bgCtx) }() @@ -47,7 +47,7 @@ func TestOCSP(t *testing.T) { }) t.Run("tlsInsecure", func(t *testing.T) { clientOpts := createInsecureOCSPClientOptions(cs.Original) - client, err := Connect(bgCtx, clientOpts) + client, err := Connect(clientOpts) assert.Nil(t, err, "Connect error: %v", err) defer func() { _ = client.Disconnect(bgCtx) }() diff --git a/mongo/options/example_test.go b/mongo/options/example_test.go index 1c5fbe4356..f3dc65d1f5 100644 --- a/mongo/options/example_test.go +++ b/mongo/options/example_test.go @@ -53,7 +53,7 @@ func ExampleClientOptions_SetLoggerOptions_customLogger() { ApplyURI("mongodb://localhost:27017"). SetLoggerOptions(loggerOptions) - client, err := mongo.Connect(context.TODO(), clientOptions) + client, err := mongo.Connect(clientOptions) if err != nil { log.Fatalf("error connecting to MongoDB: %v", err) diff --git a/mongo/readpref/options_example_test.go b/mongo/readpref/options_example_test.go index af4e220ae6..bdff555d34 100644 --- a/mongo/readpref/options_example_test.go +++ b/mongo/readpref/options_example_test.go @@ -7,8 +7,6 @@ package readpref_test import ( - "context" - "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/readpref" @@ -27,7 +25,7 @@ func ExampleWithTags() { ApplyURI("mongodb://localhost:27017"). SetReadPreference(rp) - _, err := mongo.Connect(context.Background(), opts) + _, err := mongo.Connect(opts) if err != nil { panic(err) } @@ -55,7 +53,7 @@ func ExampleWithTagSets() { ApplyURI("mongodb://localhost"). SetReadPreference(rp) - _, err := mongo.Connect(context.Background(), opts) + _, err := mongo.Connect(opts) if err != nil { panic(err) } diff --git a/mongo/with_transactions_test.go b/mongo/with_transactions_test.go index 24a253059d..24fa280e6f 100644 --- a/mongo/with_transactions_test.go +++ b/mongo/with_transactions_test.go @@ -576,7 +576,7 @@ func setupConvenientTransactions(t *testing.T, extraClientOpts ...*options.Clien fullClientOpts := []*options.ClientOptions{baseClientOpts} fullClientOpts = append(fullClientOpts, extraClientOpts...) - client, err := Connect(bgCtx, fullClientOpts...) + client, err := Connect(fullClientOpts...) assert.Nil(t, err, "Connect error: %v", err) version, err := getServerVersion(client.Database("admin")) @@ -593,7 +593,7 @@ func setupConvenientTransactions(t *testing.T, extraClientOpts ...*options.Clien // For sharded clusters, disconnect the previous Client and create a new one that's pinned to a single mongos. _ = client.Disconnect(bgCtx) fullClientOpts = append(fullClientOpts, options.Client().SetHosts([]string{cs.Hosts[0]})) - client, err = Connect(bgCtx, fullClientOpts...) + client, err = Connect(fullClientOpts...) assert.Nil(t, err, "Connect error: %v", err) return client } diff --git a/mongo/writeconcern/writeconcern_example_test.go b/mongo/writeconcern/writeconcern_example_test.go index dda4b15e9c..36208805f0 100644 --- a/mongo/writeconcern/writeconcern_example_test.go +++ b/mongo/writeconcern/writeconcern_example_test.go @@ -7,8 +7,6 @@ package writeconcern_test import ( - "context" - "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/writeconcern" @@ -23,7 +21,7 @@ func Example_majority() { ApplyURI("mongodb://localhost:27017"). SetWriteConcern(wc) - _, err := mongo.Connect(context.Background(), opts) + _, err := mongo.Connect(opts) if err != nil { panic(err) } @@ -41,7 +39,7 @@ func Example_w2Journaled() { ApplyURI("mongodb://localhost:27017"). SetWriteConcern(wc) - _, err := mongo.Connect(context.Background(), opts) + _, err := mongo.Connect(opts) if err != nil { panic(err) }