Skip to content

Commit

Permalink
MongoDB - Fix write_concern param (#18546)
Browse files Browse the repository at this point in the history
* fix writeconcern defaulting to majority

* add changelog

* restart CI tests

* fix tests

* add package
  • Loading branch information
Zlaticanin authored Dec 23, 2022
1 parent 4a6a41e commit 159b60a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/18546.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
database/mongodb: Fix writeConcern set to be applied to any query made on the database
```
12 changes: 11 additions & 1 deletion plugins/database/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,19 @@ func (m *MongoDB) DeleteUser(ctx context.Context, req dbplugin.DeleteUserRequest
db = "admin"
}

// Set the write concern. The default is majority.
writeConcern := writeconcern.New(writeconcern.WMajority())
opts, err := m.getWriteConcern()
if err != nil {
return dbplugin.DeleteUserResponse{}, err
}
if opts != nil {
writeConcern = opts.WriteConcern
}

dropUserCmd := &dropUserCommand{
Username: req.Username,
WriteConcern: writeconcern.New(writeconcern.WMajority()),
WriteConcern: writeConcern,
}

err = m.runCommandWithRetry(ctx, db, dropUserCmd)
Expand Down

0 comments on commit 159b60a

Please sign in to comment.