Skip to content

Commit

Permalink
feat(retryable-writes): add support for retryWrites cs option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mbroadst committed Dec 4, 2017
1 parent 796998b commit 2321870
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
3 changes: 2 additions & 1 deletion lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ var legalOptionNames = [
'promoteBuffers',
'promoteLongs',
'promoteValues',
'compression'
'compression',
'retryWrites'
];

/**
Expand Down
10 changes: 7 additions & 3 deletions lib/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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'));
}
Expand Down Expand Up @@ -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`);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2321870

Please sign in to comment.