From 23218703a81b96679ff862e2b2c4653bef8aa4af Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Sun, 3 Dec 2017 14:21:41 -0500 Subject: [PATCH] feat(retryable-writes): add support for `retryWrites` cs option This allows users to enable support for retryable writes through the connection string. The option is simply propagated to the core driver where all the actual work is done. NODE-1105 --- lib/collection.js | 3 +++ lib/db.js | 3 ++- lib/url_parser.js | 10 +++++++--- package.json | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/collection.js b/lib/collection.js index 2ee6c0bbe1..519f105a66 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -3237,6 +3237,9 @@ var writeConcern = function(target, db, col, options) { target.writeConcern = db.writeConcern; } + // NOTE: there is probably a much better place for this + if (db.s.options.retryWrites) target.retryWrites = true; + return target; }; diff --git a/lib/db.js b/lib/db.js index 99d24b3ba8..adaa886a76 100644 --- a/lib/db.js +++ b/lib/db.js @@ -106,7 +106,8 @@ var legalOptionNames = [ 'promoteBuffers', 'promoteLongs', 'promoteValues', - 'compression' + 'compression', + 'retryWrites' ]; /** diff --git a/lib/url_parser.js b/lib/url_parser.js index 1412045faa..484979177e 100644 --- a/lib/url_parser.js +++ b/lib/url_parser.js @@ -3,7 +3,6 @@ var ReadPreference = require('./read_preference'), parser = require('url'), f = require('util').format, - assign = require('./utils').assign, Logger = require('mongodb-core').Logger, dns = require('dns'); @@ -17,7 +16,6 @@ module.exports = function(url, options, callback) { } if (result.protocol === 'mongodb+srv:') { - if (result.hostname.split('.').length < 3) { return callback(new Error('URI does not have hostname, domain name and tld')); } @@ -552,6 +550,12 @@ function parseConnectionString(url, options) { compression.zlibCompressionLevel = zlibCompressionLevel; serverOptions.compression = compression; break; + case 'retryWrites': + dbOptions.retryWrites = value === 'true'; + break; + case 'minSize': + dbOptions.minSize = parseInt(value, 10); + break; default: var logger = Logger('URL Parser'); logger.warn(`${name} is not supported as a connection string option`); @@ -577,7 +581,7 @@ function parseConnectionString(url, options) { } // make sure that user-provided options are applied with priority - dbOptions = assign(dbOptions, options); + dbOptions = Object.assign(dbOptions, options); // Add servers to result object.servers = servers; diff --git a/package.json b/package.json index 79a0a06a3c..5fa01163cd 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "official" ], "dependencies": { - "mongodb-core": "mongodb-js/mongodb-core#6510d7d3d82d84cc0811a853355deaa918b96941" + "mongodb-core": "mongodb-js/mongodb-core#0d74dfd32566d9ab8ebe9ae4b9af736e582e5533" }, "devDependencies": { "betterbenchmarks": "^0.1.0",