Details
-
Task
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
Description
I saw this code:
// mongo-go-driver/mongo/database.go
|
|
|
func (db *Database) RunCommand(ctx context.Context, runCommand interface{}) (bson.Reader, error) { |
if ctx == nil { ctx = context.Background() } |
cmd := command.Command{DB: db.Name(), Command: runCommand} return dispatch.Command(ctx, cmd, db.client.topology, db.writeSelector)} |
Why default use db.writeSelector.
I want connect to Secondary node and get data from db.serverStatus(), but always get data from Primary.
Example:
|
|
if rs, err := db.RunCommand(context.Background(), bson.NewDocument(bson.EC.Int32("serverStatus", 1))); err != nil{ |
fmt.Printf("Error %s", err) |
}else { |
if elment, err := rs.Lookup("host"); err != nil{ |
fmt.Printf("Error %s", err) |
}else{ |
fmt.Println(elment.Value().StringValue())
|
}
|
}
|
Attachments
Issue Links
- is related to
-
GODRIVER-561 Database.RunCommand should use the provided read preference for server selection
-
- Closed
-