Details
-
Bug
-
Resolution: Won't Fix
-
Major - P3
-
None
-
1.8.3
-
None
Description
Summary
MongoDB server version and topology: 4.4 / master+ a slave node replica set
driver version: master
How to Reproduce
- Down the master node.Now only a slave node is on lived.
- use uri mongodb://[username]:[password]@master_ip,slave_ip/db_name
- Set the client option readPreference to primaryPreferred
- Then NewClient and ListCollections.
The code like:
package main |
|
|
import ( |
"context" |
"go.mongodb.org/mongo-driver/bson" |
"go.mongodb.org/mongo-driver/mongo" |
"go.mongodb.org/mongo-driver/mongo/options" |
"go.mongodb.org/mongo-driver/mongo/readpref" |
"log" |
)
|
|
|
func main() {
|
opts := options.Client().SetReadPreference(readpref.PrimaryPreferred())
|
client, err := mongo.NewClient(options.Client().ApplyURI(""), opts) |
if err != nil { |
log.Fatal(err)
|
}
|
|
if err := client.Connect(context.Background()); err != nil { |
log.Fatal(err)
|
}
|
|
_, err = client.Database("dbName").ListCollections(context.Background(), bson.D{}) |
if err != nil { |
log.Fatal(err)
|
}
|
}
|
It will return error like:
server selection error: server selection timeout, current topology: {Type: ReplicaSetNoPrimary}
By reading source code of mongo-go-driver,I think the problem be here:

Attachments
Issue Links
- related to
-
DRIVERS-1186 Allow db/collection/index enumeration to respect read preference
-
- Closed
-