Skip to content

Commit

Permalink
fix: support write concern provided as string in fromOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Feb 11, 2020
1 parent c1ed2c1 commit 637f428
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/write_concern.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const kWriteConcernKeys = new Set(['w', 'wtimeout', 'j', 'fsync']);

/**
* The **WriteConcern** class is a class that represents a MongoDB WriteConcern.
* @class
Expand Down Expand Up @@ -51,6 +53,14 @@ class WriteConcern {
}

if (options.writeConcern) {
if (typeof options.writeConcern === 'string') {
return new WriteConcern(options.writeConcern);
}

if (!Object.keys(options.writeConcern).some(key => kWriteConcernKeys.has(key))) {
return;
}

return new WriteConcern(
options.writeConcern.w,
options.writeConcern.wtimeout,
Expand Down

0 comments on commit 637f428

Please sign in to comment.