Skip to content

Commit 0516d93

Browse files
authored
feat: Deprecate top-level write concern option keys (#2624)
Deprecates top-level write concern options, which will be removed in 4.0. These options should now be specified under the `writeConcern` option. NODE-1722
1 parent e0d0119 commit 0516d93

File tree

12 files changed

+214
-139
lines changed

12 files changed

+214
-139
lines changed

lib/admin.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ Admin.prototype.ping = function(options, callback) {
166166
* @param {string} username The username.
167167
* @param {string} password The password.
168168
* @param {object} [options] Optional settings.
169-
* @param {(number|string)} [options.w] The write concern.
170-
* @param {number} [options.wtimeout] The write concern timeout.
171-
* @param {boolean} [options.j=false] Specify a journal write concern.
172-
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
169+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
170+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
171+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
172+
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
173+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
173174
* @param {object} [options.customData] Custom data associated with the user (only Mongodb 2.6 or higher)
174175
* @param {object[]} [options.roles] Roles associated with the created user (only Mongodb 2.6 or higher)
175176
* @param {ClientSession} [options.session] optional session to use for this operation
@@ -203,10 +204,11 @@ Admin.prototype.addUser = function(username, password, options, callback) {
203204
* @method
204205
* @param {string} username The username.
205206
* @param {object} [options] Optional settings.
206-
* @param {(number|string)} [options.w] The write concern.
207-
* @param {number} [options.wtimeout] The write concern timeout.
208-
* @param {boolean} [options.j=false] Specify a journal write concern.
209-
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
207+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
208+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
209+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
210+
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
211+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
210212
* @param {ClientSession} [options.session] optional session to use for this operation
211213
* @param {Admin~resultCallback} [callback] The command result callback
212214
* @return {Promise} returns Promise if no callback passed

lib/bulk/common.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,10 +1125,11 @@ class BulkOperationBase {
11251125
* @method
11261126
* @param {WriteConcern} [_writeConcern] Optional write concern. Can also be specified through options.
11271127
* @param {object} [options] Optional settings.
1128-
* @param {(number|string)} [options.w] The write concern.
1129-
* @param {number} [options.wtimeout] The write concern timeout.
1130-
* @param {boolean} [options.j=false] Specify a journal write concern.
1131-
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
1128+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
1129+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
1130+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
1131+
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
1132+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
11321133
* @param {BulkOperationBase~resultCallback} [callback] A callback that will be invoked when bulkWrite finishes/errors
11331134
* @throws {MongoError} Throws error if the bulk object has already been executed
11341135
* @throws {MongoError} Throws error if the bulk object does not have any operations

lib/collection.js

Lines changed: 80 additions & 61 deletions
Large diffs are not rendered by default.

lib/db.js

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const legalOptionNames = [
7272
'wtimeout',
7373
'fsync',
7474
'j',
75+
'writeConcern',
7576
'readPreference',
7677
'readPreferenceTags',
7778
'native_parser',
@@ -105,9 +106,10 @@ const legalOptionNames = [
105106
* @param {(Server|ReplSet|Mongos)} topology The server topology for the database.
106107
* @param {object} [options] Optional settings.
107108
* @param {string} [options.authSource] If the database authentication is dependent on another databaseName.
108-
* @param {(number|string)} [options.w] The write concern.
109-
* @param {number} [options.wtimeout] The write concern timeout.
110-
* @param {boolean} [options.j=false] Specify a journal write concern.
109+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
110+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
111+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
112+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
111113
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
112114
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
113115
* @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
@@ -399,9 +401,10 @@ const collectionKeys = [
399401
* @method
400402
* @param {string} name the collection name we wish to access.
401403
* @param {object} [options] Optional settings.
402-
* @param {(number|string)} [options.w] The write concern.
403-
* @param {number} [options.wtimeout] The write concern timeout.
404-
* @param {boolean} [options.j=false] Specify a journal write concern.
404+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
405+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
406+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
407+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
405408
* @param {boolean} [options.raw=false] Return document results as raw BSON buffers.
406409
* @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys.
407410
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
@@ -493,9 +496,10 @@ Db.prototype.collection = function(name, options, callback) {
493496
* @method
494497
* @param {string} name the collection name we wish to access.
495498
* @param {object} [options] Optional settings.
496-
* @param {(number|string)} [options.w] The write concern.
497-
* @param {number} [options.wtimeout] The write concern timeout.
498-
* @param {boolean} [options.j=false] Specify a journal write concern.
499+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
500+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
501+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
502+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
499503
* @param {boolean} [options.raw=false] Return document results as raw BSON buffers.
500504
* @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys.
501505
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
@@ -521,7 +525,7 @@ Db.prototype.collection = function(name, options, callback) {
521525
Db.prototype.createCollection = deprecateOptions(
522526
{
523527
name: 'Db.createCollection',
524-
deprecatedOptions: ['autoIndexId', 'strict'],
528+
deprecatedOptions: ['autoIndexId', 'strict', 'w', 'wtimeout', 'j'],
525529
optionsIndex: 1
526530
},
527531
function(name, options, callback) {
@@ -651,10 +655,10 @@ Db.prototype.renameCollection = function(fromCollection, toCollection, options,
651655
* @method
652656
* @param {string} name Name of collection to drop
653657
* @param {Object} [options] Optional settings
654-
* @param {WriteConcern} [options.writeConcern] A full WriteConcern object
655-
* @param {(number|string)} [options.w] The write concern
656-
* @param {number} [options.wtimeout] The write concern timeout
657-
* @param {boolean} [options.j] The journal write concern
658+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
659+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
660+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
661+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
658662
* @param {ClientSession} [options.session] optional session to use for this operation
659663
* @param {Db~resultCallback} [callback] The results callback
660664
* @return {Promise} returns Promise if no callback passed
@@ -734,9 +738,10 @@ Db.prototype.executeDbAdminCommand = function(selector, options, callback) {
734738
* @param {string} name Name of the collection to create the index on.
735739
* @param {(string|object)} fieldOrSpec Defines the index.
736740
* @param {object} [options] Optional settings.
737-
* @param {(number|string)} [options.w] The write concern.
738-
* @param {number} [options.wtimeout] The write concern timeout.
739-
* @param {boolean} [options.j=false] Specify a journal write concern.
741+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
742+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
743+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
744+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
740745
* @param {boolean} [options.unique=false] Creates an unique index.
741746
* @param {boolean} [options.sparse=false] Creates a sparse index.
742747
* @param {boolean} [options.background=false] Creates the index in the background, yielding whenever possible.
@@ -768,9 +773,10 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) {
768773
* @param {string} name The index name
769774
* @param {(string|object)} fieldOrSpec Defines the index.
770775
* @param {object} [options] Optional settings.
771-
* @param {(number|string)} [options.w] The write concern.
772-
* @param {number} [options.wtimeout] The write concern timeout.
773-
* @param {boolean} [options.j=false] Specify a journal write concern.
776+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
777+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
778+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
779+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
774780
* @param {boolean} [options.unique=false] Creates an unique index.
775781
* @param {boolean} [options.sparse=false] Creates a sparse index.
776782
* @param {boolean} [options.background=false] Creates the index in the background, yielding whenever possible.
@@ -808,9 +814,10 @@ Db.prototype.addChild = function(db) {
808814
* @param {string} username The username.
809815
* @param {string} password The password.
810816
* @param {object} [options] Optional settings.
811-
* @param {(number|string)} [options.w] The write concern.
812-
* @param {number} [options.wtimeout] The write concern timeout.
813-
* @param {boolean} [options.j=false] Specify a journal write concern.
817+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
818+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
819+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
820+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
814821
* @param {object} [options.customData] Custom data associated with the user (only Mongodb 2.6 or higher)
815822
* @param {object[]} [options.roles] Roles associated with the created user (only Mongodb 2.6 or higher)
816823
* @param {ClientSession} [options.session] optional session to use for this operation
@@ -837,9 +844,10 @@ Db.prototype.addUser = function(username, password, options, callback) {
837844
* @method
838845
* @param {string} username The username.
839846
* @param {object} [options] Optional settings.
840-
* @param {(number|string)} [options.w] The write concern.
841-
* @param {number} [options.wtimeout] The write concern timeout.
842-
* @param {boolean} [options.j=false] Specify a journal write concern.
847+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
848+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
849+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
850+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
843851
* @param {ClientSession} [options.session] optional session to use for this operation
844852
* @param {Db~resultCallback} [callback] The command result callback
845853
* @return {Promise} returns Promise if no callback passed

lib/gridfs-stream/upload.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ module.exports = GridFSBucketWriteStream;
2222
* @param {object} [options] Optional settings.
2323
* @param {string|number|object} [options.id] Custom file id for the GridFS file.
2424
* @param {number} [options.chunkSizeBytes] The chunk size to use, in bytes
25-
* @param {number} [options.w] The write concern
26-
* @param {number} [options.wtimeout] The write concern timeout
27-
* @param {number} [options.j] The journal write concern
25+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
26+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
27+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
28+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
2829
* @param {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
2930
* @fires GridFSBucketWriteStream#error
3031
* @fires GridFSBucketWriteStream#finish

lib/gridfs/grid_store.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ const deprecationFn = deprecate(() => {},
7373
* @param {string} [filename] optional filename for this file, no unique constrain on the field
7474
* @param {string} mode set the mode for this file.
7575
* @param {object} [options] Optional settings.
76-
* @param {(number|string)} [options.w] The write concern.
77-
* @param {number} [options.wtimeout] The write concern timeout.
78-
* @param {boolean} [options.j=false] Specify a journal write concern.
79-
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
76+
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
77+
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
78+
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
79+
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
80+
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
8081
* @param {string} [options.root] Root collection to use. Defaults to **{GridStore.DEFAULT_ROOT_COLLECTION}**.
8182
* @param {string} [options.content_type] MIME type of the file. Defaults to **{GridStore.DEFAULT_CONTENT_TYPE}**.
8283
* @param {number} [options.chunk_size=261120] Size for the chunk. Defaults to **{Chunk.DEFAULT_CHUNK_SIZE}**.
@@ -1572,12 +1573,13 @@ var _writeNormal = function(self, data, close, options, callback) {
15721573
* @ignore
15731574
*/
15741575
var _setWriteConcernHash = function(options) {
1576+
const baseOptions = Object.assign(options, options.writeConcern);
15751577
var finalOptions = {};
1576-
if (options.w != null) finalOptions.w = options.w;
1577-
if (options.journal === true) finalOptions.j = options.journal;
1578-
if (options.j === true) finalOptions.j = options.j;
1579-
if (options.fsync === true) finalOptions.fsync = options.fsync;
1580-
if (options.wtimeout != null) finalOptions.wtimeout = options.wtimeout;
1578+
if (baseOptions.w != null) finalOptions.w = baseOptions.w;
1579+
if (baseOptions.journal === true) finalOptions.j = baseOptions.journal;
1580+
if (baseOptions.j === true) finalOptions.j = baseOptions.j;
1581+
if (baseOptions.fsync === true) finalOptions.fsync = baseOptions.fsync;
1582+
if (baseOptions.wtimeout != null) finalOptions.wtimeout = baseOptions.wtimeout;
15811583
return finalOptions;
15821584
};
15831585

@@ -1591,6 +1593,7 @@ var _getWriteConcern = function(self, options) {
15911593

15921594
// Local options verification
15931595
if (
1596+
options.writeConcern != null ||
15941597
options.w != null ||
15951598
typeof options.j === 'boolean' ||
15961599
typeof options.journal === 'boolean' ||
@@ -1602,6 +1605,7 @@ var _getWriteConcern = function(self, options) {
16021605
} else if (typeof options.safe === 'boolean') {
16031606
finalOptions = { w: options.safe ? 1 : 0 };
16041607
} else if (
1608+
self.options.writeConcern != null ||
16051609
self.options.w != null ||
16061610
typeof self.options.j === 'boolean' ||
16071611
typeof self.options.journal === 'boolean' ||

0 commit comments

Comments
 (0)