Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-451

Why runCommand execute in the Primary

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 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())
         }
      }
      

       

       

            Assignee:
            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            Reporter:
            xjxyxgq GuoqiangXu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: