MongoDB Bongo/mgo Go driver mostly routes reads to a single secondary

Hi,

I’m currently running a MongoDB replica set in production, and I’ve noticed that my Go service is routing most of its read requests to only one of the secondary nodes, even though other secondaries are healthy and available. This is causing uneven load and occasional I/O timeout issues.

Here’s my setup and what I’ve observed:


Setup:

  • MongoDB Replica Set: 1 primary, 2 secondaries
  • Driver: bongo ORM, which internally uses the mgo.v2 MongoDB driver
  • Connection Config in Go:
config := &bongo.Config{
    Database: "core",
    DialInfo: &mgo.DialInfo{
        AppName:     "core-client",
        Addrs:       []string{"<replica-set-hosts>"},
        Timeout:     3 * time.Second,
        PoolLimit:   20,
        PoolTimeout: 2 * time.Second,
        Username:    "<user>",
        Password:    "<pass>",
        MinPoolSize: 5,
    },
}
  • No explicit read preference is set in the code. Based on the bongo source and default behavior of mgo, it defaults to:
session.SetMode(mgo.SecondaryPreferred, true)

Observations:

  • Almost all read queries go to one secondary
  • The other secondary node has very low read load
  • Confirmed this from Mongo logs and GCP VM metrics
  • Mongo logs show slow queries with readPreference set to secondaryPreferred

My Goal:

I want to distribute read queries across all secondary nodes in a more balanced way.


What I’ve tried:

  1. Verified there’s no explicit readPreference override in my code
  2. Verified from logs that the queries are indeed going with secondaryPreferred mode
  3. Checked that all secondaries are healthy and eligible
  4. Checked that mgo chooses the nearest secondary (lowest ping), and then sticks with it

My Questions:

  1. Is there any way to force or encourage round-robin or load-balanced behavior across all secondaries using the mgo driver (or bongo)?
  2. Would setting mgo.Nearest help, and how can I do that when using bongo? Is it safe to override the session mode after initializing Bongo?
  3. Are there other flags/settings in MongoDB or the driver that influence this selection (like latency thresholds)?
  4. Could I be misinterpreting the nearest behavior - does it actually round-robin among multiple low-latency nodes?
  5. Is switching to the official MongoDB Go Driver the better approach for more advanced control? If yes, then how ?