Skip to content

Commit

Permalink
Set read/write concern for command type
Browse files Browse the repository at this point in the history
... and not generally for all commands
  • Loading branch information
boris-ilijic committed May 6, 2024
1 parent aa4c146 commit cb79d42
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions pbm/connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,7 @@ func (l *clientImpl) ConfigDatabase() *mongo.Database {
}

func (l *clientImpl) AdminCommand(ctx context.Context, cmd bson.D, opts ...*options.RunCmdOptions) *mongo.SingleResult {
cmd = append(cmd,
bson.E{"readConcern", l.options.ReadConcern},
bson.E{"writeConcern", l.options.WriteConcern},
)
cmd = l.applyOptonsFromConnString(cmd)
return l.client.Database(defs.DB).RunCommand(ctx, cmd, opts...)
}

Expand Down Expand Up @@ -294,6 +291,28 @@ func (l *clientImpl) AgentsStatusCollection() *mongo.Collection {
return l.client.Database(defs.DB).Collection(defs.AgentsStatusCollection)
}

func (l *clientImpl) applyOptonsFromConnString(cmd bson.D) bson.D {
if len(cmd) == 0 {
return cmd
}

cmdName := cmd[0].Key
switch cmdName {
case "create":
if l.options.WriteConcern != nil {
cmd = append(cmd, bson.E{"writeConcern", l.options.WriteConcern})
}
default:
// do nothing for all other commands:
// flushRouterConfig
// _configsvrBalancerStart
// _configsvrBalancerStop
// _configsvrBalancerStatus
}

return cmd
}

var ErrInvalidConnection = errors.New("invalid mongo connection")

type Client interface {
Expand Down

0 comments on commit cb79d42

Please sign in to comment.