Skip to content

Commit cb79d42

Browse files
committed
Set read/write concern for command type
... and not generally for all commands
1 parent aa4c146 commit cb79d42

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

pbm/connect/connect.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,7 @@ func (l *clientImpl) ConfigDatabase() *mongo.Database {
247247
}
248248

249249
func (l *clientImpl) AdminCommand(ctx context.Context, cmd bson.D, opts ...*options.RunCmdOptions) *mongo.SingleResult {
250-
cmd = append(cmd,
251-
bson.E{"readConcern", l.options.ReadConcern},
252-
bson.E{"writeConcern", l.options.WriteConcern},
253-
)
250+
cmd = l.applyOptonsFromConnString(cmd)
254251
return l.client.Database(defs.DB).RunCommand(ctx, cmd, opts...)
255252
}
256253

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

294+
func (l *clientImpl) applyOptonsFromConnString(cmd bson.D) bson.D {
295+
if len(cmd) == 0 {
296+
return cmd
297+
}
298+
299+
cmdName := cmd[0].Key
300+
switch cmdName {
301+
case "create":
302+
if l.options.WriteConcern != nil {
303+
cmd = append(cmd, bson.E{"writeConcern", l.options.WriteConcern})
304+
}
305+
default:
306+
// do nothing for all other commands:
307+
// flushRouterConfig
308+
// _configsvrBalancerStart
309+
// _configsvrBalancerStop
310+
// _configsvrBalancerStatus
311+
}
312+
313+
return cmd
314+
}
315+
297316
var ErrInvalidConnection = errors.New("invalid mongo connection")
298317

299318
type Client interface {

0 commit comments

Comments
 (0)