From d9b8fb6877f9d9c29ba11a78ea37ea735398d55d Mon Sep 17 00:00:00 2001 From: Milena Zlaticanin <60530402+Zlaticanin@users.noreply.github.com> Date: Fri, 23 Dec 2022 17:14:41 -0600 Subject: [PATCH] MongoDB - Fix write_concern param (#18546) * fix writeconcern defaulting to majority * add changelog * restart CI tests * fix tests * add package --- changelog/18546.txt | 3 +++ plugins/database/mongodb/mongodb.go | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 changelog/18546.txt diff --git a/changelog/18546.txt b/changelog/18546.txt new file mode 100644 index 000000000..48bc906d5 --- /dev/null +++ b/changelog/18546.txt @@ -0,0 +1,3 @@ +```release-note:bug +database/mongodb: Fix writeConcern set to be applied to any query made on the database +``` \ No newline at end of file diff --git a/plugins/database/mongodb/mongodb.go b/plugins/database/mongodb/mongodb.go index 13231fdef..6cb511b89 100644 --- a/plugins/database/mongodb/mongodb.go +++ b/plugins/database/mongodb/mongodb.go @@ -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)