Details
-
Task
-
Resolution: Done
-
Major - P3
-
None
-
0.0.18
-
None
-
2 mongodb with docker (replica set configured successfully, shell connection works fine)
macOS 10.14.1
go 1.11.2 with go module
Description
ctx := context.Background()
|
|
|
clientOptions := &options.ClientOptions{}
|
clientOptions.SetHosts([]string\{"mongodb://localhost:27017", "mongodb://localhost:27018"})
|
clientOptions.SetReadPreference(readpref.Primary())
|
clientOptions.SetServerSelectionTimeout(time.Duration(2*time.Second))
|
|
|
client, err := mongo.NewClientWithOptions("mongodb://localhost:27017,localhost:27018", clientOptions)
|
if err != nil {
|
panic(err)
|
}
|
|
|
err = client.Connect(ctx)
|
if err != nil {
|
panic(err)
|
}
|
|
|
dbs, err := client.ListDatabaseNames(ctx, bson.D{})
|
if err != nil {
|
panic(err)
|
}
|
|
|
fmt.Println(dbs)
|
but result is: panic: server selection timeout
I also added replicaSet=rs0 option but result was same.
Does this driver not yet support replica set?