Skip to content

Commit 2321870

Browse files
committed
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
1 parent 796998b commit 2321870

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

lib/collection.js

+3
Original file line numberDiff line numberDiff line change
@@ -3237,6 +3237,9 @@ var writeConcern = function(target, db, col, options) {
32373237
target.writeConcern = db.writeConcern;
32383238
}
32393239

3240+
// NOTE: there is probably a much better place for this
3241+
if (db.s.options.retryWrites) target.retryWrites = true;
3242+
32403243
return target;
32413244
};
32423245

lib/db.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ var legalOptionNames = [
106106
'promoteBuffers',
107107
'promoteLongs',
108108
'promoteValues',
109-
'compression'
109+
'compression',
110+
'retryWrites'
110111
];
111112

112113
/**

lib/url_parser.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
var ReadPreference = require('./read_preference'),
44
parser = require('url'),
55
f = require('util').format,
6-
assign = require('./utils').assign,
76
Logger = require('mongodb-core').Logger,
87
dns = require('dns');
98

@@ -17,7 +16,6 @@ module.exports = function(url, options, callback) {
1716
}
1817

1918
if (result.protocol === 'mongodb+srv:') {
20-
2119
if (result.hostname.split('.').length < 3) {
2220
return callback(new Error('URI does not have hostname, domain name and tld'));
2321
}
@@ -552,6 +550,12 @@ function parseConnectionString(url, options) {
552550
compression.zlibCompressionLevel = zlibCompressionLevel;
553551
serverOptions.compression = compression;
554552
break;
553+
case 'retryWrites':
554+
dbOptions.retryWrites = value === 'true';
555+
break;
556+
case 'minSize':
557+
dbOptions.minSize = parseInt(value, 10);
558+
break;
555559
default:
556560
var logger = Logger('URL Parser');
557561
logger.warn(`${name} is not supported as a connection string option`);
@@ -577,7 +581,7 @@ function parseConnectionString(url, options) {
577581
}
578582

579583
// make sure that user-provided options are applied with priority
580-
dbOptions = assign(dbOptions, options);
584+
dbOptions = Object.assign(dbOptions, options);
581585

582586
// Add servers to result
583587
object.servers = servers;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"official"
1414
],
1515
"dependencies": {
16-
"mongodb-core": "mongodb-js/mongodb-core#6510d7d3d82d84cc0811a853355deaa918b96941"
16+
"mongodb-core": "mongodb-js/mongodb-core#0d74dfd32566d9ab8ebe9ae4b9af736e582e5533"
1717
},
1818
"devDependencies": {
1919
"betterbenchmarks": "^0.1.0",

0 commit comments

Comments
 (0)