Skip to content

Commit 637f428

Browse files
committed
fix: support write concern provided as string in fromOptions
1 parent c1ed2c1 commit 637f428

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/write_concern.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const kWriteConcernKeys = new Set(['w', 'wtimeout', 'j', 'fsync']);
4+
35
/**
46
* The **WriteConcern** class is a class that represents a MongoDB WriteConcern.
57
* @class
@@ -51,6 +53,14 @@ class WriteConcern {
5153
}
5254

5355
if (options.writeConcern) {
56+
if (typeof options.writeConcern === 'string') {
57+
return new WriteConcern(options.writeConcern);
58+
}
59+
60+
if (!Object.keys(options.writeConcern).some(key => kWriteConcernKeys.has(key))) {
61+
return;
62+
}
63+
5464
return new WriteConcern(
5565
options.writeConcern.w,
5666
options.writeConcern.wtimeout,

0 commit comments

Comments
 (0)