-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: CRUD
-
None
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()) } }
- is related to
-
GODRIVER-561 Database.RunCommand should use the provided read preference for server selection
- Closed