Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Deprecate top-level write concern option keys #2624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ Admin.prototype.ping = function(options, callback) {
* @param {string} username The username.
* @param {string} password The password.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {object} [options.customData] Custom data associated with the user (only Mongodb 2.6 or higher)
* @param {object[]} [options.roles] Roles associated with the created user (only Mongodb 2.6 or higher)
* @param {ClientSession} [options.session] optional session to use for this operation
Expand Down Expand Up @@ -203,10 +204,11 @@ Admin.prototype.addUser = function(username, password, options, callback) {
* @method
* @param {string} username The username.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {ClientSession} [options.session] optional session to use for this operation
* @param {Admin~resultCallback} [callback] The command result callback
* @return {Promise} returns Promise if no callback passed
Expand Down
9 changes: 5 additions & 4 deletions lib/bulk/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,10 +1125,11 @@ class BulkOperationBase {
* @method
* @param {WriteConcern} [_writeConcern] Optional write concern. Can also be specified through options.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {BulkOperationBase~resultCallback} [callback] A callback that will be invoked when bulkWrite finishes/errors
* @throws {MongoError} Throws error if the bulk object has already been executed
* @throws {MongoError} Throws error if the bulk object does not have any operations
Expand Down
141 changes: 80 additions & 61 deletions lib/collection.js

Large diffs are not rendered by default.

60 changes: 34 additions & 26 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const legalOptionNames = [
'wtimeout',
'fsync',
'j',
'writeConcern',
'readPreference',
'readPreferenceTags',
'native_parser',
Expand Down Expand Up @@ -105,9 +106,10 @@ const legalOptionNames = [
* @param {(Server|ReplSet|Mongos)} topology The server topology for the database.
* @param {object} [options] Optional settings.
* @param {string} [options.authSource] If the database authentication is dependent on another databaseName.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
* @param {Boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
Expand Down Expand Up @@ -399,9 +401,10 @@ const collectionKeys = [
* @method
* @param {string} name the collection name we wish to access.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {boolean} [options.raw=false] Return document results as raw BSON buffers.
* @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys.
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
Expand Down Expand Up @@ -493,9 +496,10 @@ Db.prototype.collection = function(name, options, callback) {
* @method
* @param {string} name the collection name we wish to access.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {boolean} [options.raw=false] Return document results as raw BSON buffers.
* @param {object} [options.pkFactory] A primary key factory object for generation of custom _id keys.
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
Expand All @@ -521,7 +525,7 @@ Db.prototype.collection = function(name, options, callback) {
Db.prototype.createCollection = deprecateOptions(
{
name: 'Db.createCollection',
deprecatedOptions: ['autoIndexId', 'strict'],
deprecatedOptions: ['autoIndexId', 'strict', 'w', 'wtimeout', 'j'],
optionsIndex: 1
},
function(name, options, callback) {
Expand Down Expand Up @@ -651,10 +655,10 @@ Db.prototype.renameCollection = function(fromCollection, toCollection, options,
* @method
* @param {string} name Name of collection to drop
* @param {Object} [options] Optional settings
* @param {WriteConcern} [options.writeConcern] A full WriteConcern object
* @param {(number|string)} [options.w] The write concern
* @param {number} [options.wtimeout] The write concern timeout
* @param {boolean} [options.j] The journal write concern
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {ClientSession} [options.session] optional session to use for this operation
* @param {Db~resultCallback} [callback] The results callback
* @return {Promise} returns Promise if no callback passed
Expand Down Expand Up @@ -734,9 +738,10 @@ Db.prototype.executeDbAdminCommand = function(selector, options, callback) {
* @param {string} name Name of the collection to create the index on.
* @param {(string|object)} fieldOrSpec Defines the index.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {boolean} [options.unique=false] Creates an unique index.
* @param {boolean} [options.sparse=false] Creates a sparse index.
* @param {boolean} [options.background=false] Creates the index in the background, yielding whenever possible.
Expand Down Expand Up @@ -768,9 +773,10 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) {
* @param {string} name The index name
* @param {(string|object)} fieldOrSpec Defines the index.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {boolean} [options.unique=false] Creates an unique index.
* @param {boolean} [options.sparse=false] Creates a sparse index.
* @param {boolean} [options.background=false] Creates the index in the background, yielding whenever possible.
Expand Down Expand Up @@ -808,9 +814,10 @@ Db.prototype.addChild = function(db) {
* @param {string} username The username.
* @param {string} password The password.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {object} [options.customData] Custom data associated with the user (only Mongodb 2.6 or higher)
* @param {object[]} [options.roles] Roles associated with the created user (only Mongodb 2.6 or higher)
* @param {ClientSession} [options.session] optional session to use for this operation
Expand All @@ -837,9 +844,10 @@ Db.prototype.addUser = function(username, password, options, callback) {
* @method
* @param {string} username The username.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {ClientSession} [options.session] optional session to use for this operation
* @param {Db~resultCallback} [callback] The command result callback
* @return {Promise} returns Promise if no callback passed
Expand Down
7 changes: 4 additions & 3 deletions lib/gridfs-stream/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ module.exports = GridFSBucketWriteStream;
* @param {object} [options] Optional settings.
* @param {string|number|object} [options.id] Custom file id for the GridFS file.
* @param {number} [options.chunkSizeBytes] The chunk size to use, in bytes
* @param {number} [options.w] The write concern
* @param {number} [options.wtimeout] The write concern timeout
* @param {number} [options.j] The journal write concern
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
* @fires GridFSBucketWriteStream#error
* @fires GridFSBucketWriteStream#finish
Expand Down
22 changes: 13 additions & 9 deletions lib/gridfs/grid_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ const deprecationFn = deprecate(() => {},
* @param {string} [filename] optional filename for this file, no unique constrain on the field
* @param {string} mode set the mode for this file.
* @param {object} [options] Optional settings.
* @param {(number|string)} [options.w] The write concern.
* @param {number} [options.wtimeout] The write concern timeout.
* @param {boolean} [options.j=false] Specify a journal write concern.
* @param {boolean} [options.fsync=false] Specify a file sync write concern.
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
* @param {boolean} [options.fsync=false] **Deprecated** Specify a file sync write concern. Use writeConcern instead.
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
* @param {string} [options.root] Root collection to use. Defaults to **{GridStore.DEFAULT_ROOT_COLLECTION}**.
* @param {string} [options.content_type] MIME type of the file. Defaults to **{GridStore.DEFAULT_CONTENT_TYPE}**.
* @param {number} [options.chunk_size=261120] Size for the chunk. Defaults to **{Chunk.DEFAULT_CHUNK_SIZE}**.
Expand Down Expand Up @@ -1572,12 +1573,13 @@ var _writeNormal = function(self, data, close, options, callback) {
* @ignore
*/
var _setWriteConcernHash = function(options) {
const baseOptions = Object.assign(options, options.writeConcern);
var finalOptions = {};
if (options.w != null) finalOptions.w = options.w;
if (options.journal === true) finalOptions.j = options.journal;
if (options.j === true) finalOptions.j = options.j;
if (options.fsync === true) finalOptions.fsync = options.fsync;
if (options.wtimeout != null) finalOptions.wtimeout = options.wtimeout;
if (baseOptions.w != null) finalOptions.w = baseOptions.w;
if (baseOptions.journal === true) finalOptions.j = baseOptions.journal;
if (baseOptions.j === true) finalOptions.j = baseOptions.j;
if (baseOptions.fsync === true) finalOptions.fsync = baseOptions.fsync;
if (baseOptions.wtimeout != null) finalOptions.wtimeout = baseOptions.wtimeout;
return finalOptions;
};

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

// Local options verification
if (
options.writeConcern != null ||
options.w != null ||
typeof options.j === 'boolean' ||
typeof options.journal === 'boolean' ||
Expand All @@ -1602,6 +1605,7 @@ var _getWriteConcern = function(self, options) {
} else if (typeof options.safe === 'boolean') {
finalOptions = { w: options.safe ? 1 : 0 };
} else if (
self.options.writeConcern != null ||
self.options.w != null ||
typeof self.options.j === 'boolean' ||
typeof self.options.journal === 'boolean' ||
Expand Down
Loading