Skip to content

Commit 39b1cfb

Browse files
committed
[mongo] Use the primary node only if it belongs to the given replica set
1 parent 6065f07 commit 39b1cfb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mongo/db.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ type Config struct {
2424
TLS *nftls.Config `mapstructure:"tls_conf"`
2525
DB string `mapstructure:"db"`
2626
Servers []string `mapstructure:"servers"`
27+
ReplSetName string `mapstructure:"replset_name"`
2728
ConnTimeout int64 `mapstructure:"conn_timeout"`
2829
}
2930

3031
func Connect(config *Config, log *logrus.Entry) (*mgo.Database, error) {
3132
info := &mgo.DialInfo{
32-
Addrs: config.Servers,
33-
Timeout: time.Second * time.Duration(config.ConnTimeout),
33+
Addrs: config.Servers,
34+
ReplicaSetName: config.ReplSetName,
35+
Timeout: time.Second * time.Duration(config.ConnTimeout),
3436
}
3537

3638
if config.TLS != nil {

0 commit comments

Comments
 (0)