|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | const applyWriteConcern = require('../utils').applyWriteConcern;
|
| 4 | +const applyRetryableWrites = require('../utils').applyRetryableWrites; |
4 | 5 | const checkCollectionName = require('../utils').checkCollectionName;
|
5 | 6 | const Code = require('mongodb-core').BSON.Code;
|
6 | 7 | const createIndexDb = require('./db_ops').createIndex;
|
@@ -97,12 +98,10 @@ function bulkWrite(coll, operations, options, callback) {
|
97 | 98 | return callback(err, null);
|
98 | 99 | }
|
99 | 100 |
|
100 |
| - // Final options for write concern |
101 |
| - const finalOptions = applyWriteConcern( |
102 |
| - Object.assign({}, options), |
103 |
| - { db: coll.s.db, collection: coll }, |
104 |
| - options |
105 |
| - ); |
| 101 | + // Final options for retryable writes and write concern |
| 102 | + let finalOptions = Object.assign({}, options); |
| 103 | + finalOptions = applyRetryableWrites(finalOptions, coll.s.db); |
| 104 | + finalOptions = applyWriteConcern(finalOptions, { db: coll.s.db, collection: coll }, options); |
106 | 105 |
|
107 | 106 | const writeCon = finalOptions.writeConcern ? finalOptions.writeConcern : {};
|
108 | 107 | const capabilities = coll.s.topology.capabilities();
|
@@ -504,8 +503,10 @@ function findAndModify(coll, query, sort, doc, options, callback) {
|
504 | 503 | // No check on the documents
|
505 | 504 | options.checkKeys = false;
|
506 | 505 |
|
507 |
| - // Get the write concern settings |
508 |
| - const finalOptions = applyWriteConcern(options, { db: coll.s.db, collection: coll }, options); |
| 506 | + // Final options for retryable writes and write concern |
| 507 | + let finalOptions = Object.assign({}, options); |
| 508 | + finalOptions = applyRetryableWrites(finalOptions, coll.s.db); |
| 509 | + finalOptions = applyWriteConcern(finalOptions, { db: coll.s.db, collection: coll }, options); |
509 | 510 |
|
510 | 511 | // Decorate the findAndModify command with the write Concern
|
511 | 512 | if (finalOptions.writeConcern) {
|
@@ -805,12 +806,10 @@ function insertDocuments(coll, docs, options, callback) {
|
805 | 806 | // Ensure we are operating on an array op docs
|
806 | 807 | docs = Array.isArray(docs) ? docs : [docs];
|
807 | 808 |
|
808 |
| - // Get the write concern options |
809 |
| - const finalOptions = applyWriteConcern( |
810 |
| - Object.assign({}, options), |
811 |
| - { db: coll.s.db, collection: coll }, |
812 |
| - options |
813 |
| - ); |
| 809 | + // Final options for retryable writes and write concern |
| 810 | + let finalOptions = Object.assign({}, options); |
| 811 | + finalOptions = applyRetryableWrites(finalOptions, coll.s.db); |
| 812 | + finalOptions = applyWriteConcern(finalOptions, { db: coll.s.db, collection: coll }, options); |
814 | 813 |
|
815 | 814 | // If keep going set unordered
|
816 | 815 | if (finalOptions.keepGoing === true) finalOptions.ordered = false;
|
@@ -1138,12 +1137,10 @@ function removeDocuments(coll, selector, options, callback) {
|
1138 | 1137 | // Create an empty options object if the provided one is null
|
1139 | 1138 | options = options || {};
|
1140 | 1139 |
|
1141 |
| - // Get the write concern options |
1142 |
| - const finalOptions = applyWriteConcern( |
1143 |
| - Object.assign({}, options), |
1144 |
| - { db: coll.s.db, collection: coll }, |
1145 |
| - options |
1146 |
| - ); |
| 1140 | + // Final options for retryable writes and write concern |
| 1141 | + let finalOptions = Object.assign({}, options); |
| 1142 | + finalOptions = applyRetryableWrites(finalOptions, coll.s.db); |
| 1143 | + finalOptions = applyWriteConcern(finalOptions, { db: coll.s.db, collection: coll }, options); |
1147 | 1144 |
|
1148 | 1145 | // If selector is null set empty
|
1149 | 1146 | if (selector == null) selector = {};
|
@@ -1336,12 +1333,10 @@ function updateDocuments(coll, selector, document, options, callback) {
|
1336 | 1333 | if (document == null || typeof document !== 'object')
|
1337 | 1334 | return callback(toError('document must be a valid JavaScript object'));
|
1338 | 1335 |
|
1339 |
| - // Get the write concern options |
1340 |
| - const finalOptions = applyWriteConcern( |
1341 |
| - Object.assign({}, options), |
1342 |
| - { db: coll.s.db, collection: coll }, |
1343 |
| - options |
1344 |
| - ); |
| 1336 | + // Final options for retryable writes and write concern |
| 1337 | + let finalOptions = Object.assign({}, options); |
| 1338 | + finalOptions = applyRetryableWrites(finalOptions, coll.s.db); |
| 1339 | + finalOptions = applyWriteConcern(finalOptions, { db: coll.s.db, collection: coll }, options); |
1345 | 1340 |
|
1346 | 1341 | // Do we return the actual result document
|
1347 | 1342 | // Either use override on the function, or go back to default on either the collection
|
|
0 commit comments