Skip to content

Commit 34932b4

Browse files
committed
refactor(execute-operation): pass topology as first parameter
There is no longer any ambiguity around what is passed in as the first parameter to `executeOperation`. This allows us to optimize by removing a conditional, and centralizing options and session management to the `TopologyBase`. NODE-1088
1 parent 6ccb48c commit 34932b4

File tree

10 files changed

+126
-101
lines changed

10 files changed

+126
-101
lines changed

lib/admin.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Admin.prototype.command = function(command, options, callback) {
6969
callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
7070
options = args.length ? args.shift() : {};
7171

72-
return executeOperation(this.s.db, this.s.db.executeDbAdminCommand.bind(this.s.db), [
72+
return executeOperation(this.s.db.s.topology, this.s.db.executeDbAdminCommand.bind(this.s.db), [
7373
command,
7474
options,
7575
callback
@@ -91,7 +91,7 @@ Admin.prototype.buildInfo = function(options, callback) {
9191
if (typeof options === 'function') (callback = options), (options = {});
9292

9393
const cmd = { buildinfo: 1 };
94-
return executeOperation(this.s.db, this.s.db.executeDbAdminCommand.bind(this.s.db), [
94+
return executeOperation(this.s.db.s.topology, this.s.db.executeDbAdminCommand.bind(this.s.db), [
9595
cmd,
9696
undefined,
9797
callback
@@ -113,7 +113,7 @@ Admin.prototype.serverInfo = function(options, callback) {
113113
if (typeof options === 'function') (callback = options), (options = {});
114114

115115
const cmd = { buildinfo: 1 };
116-
return executeOperation(this.s.db, this.s.db.executeDbAdminCommand.bind(this.s.db), [
116+
return executeOperation(this.s.db.s.topology, this.s.db.executeDbAdminCommand.bind(this.s.db), [
117117
cmd,
118118
options,
119119
callback
@@ -132,7 +132,7 @@ define.classMethod('serverInfo', { callback: true, promise: true });
132132
*/
133133
Admin.prototype.serverStatus = function(options, callback) {
134134
if (typeof options === 'function') (callback = options), (options = {});
135-
return executeOperation(this.s.db, serverStatus, [this, options, callback]);
135+
return executeOperation(this.s.db.s.topology, serverStatus, [this, options, callback]);
136136
};
137137

138138
var serverStatus = function(self, options, callback) {
@@ -160,7 +160,7 @@ Admin.prototype.ping = function(options, callback) {
160160
if (typeof options === 'function') (callback = options), (options = {});
161161

162162
const cmd = { ping: 1 };
163-
return executeOperation(this.s.db, this.s.db.executeDbAdminCommand.bind(this.s.db), [
163+
return executeOperation(this.s.db.s.topology, this.s.db.executeDbAdminCommand.bind(this.s.db), [
164164
cmd,
165165
options,
166166
callback
@@ -218,7 +218,7 @@ Admin.prototype.addUser = function(username, password, options, callback) {
218218
// Set the db name to admin
219219
options.dbName = 'admin';
220220

221-
return executeOperation(this.s.db, this.s.db.addUser.bind(this.s.db), [
221+
return executeOperation(this.s.db.s.topology, this.s.db.addUser.bind(this.s.db), [
222222
username,
223223
password,
224224
options,
@@ -253,7 +253,7 @@ Admin.prototype.removeUser = function(username, options, callback) {
253253
// Set the db name
254254
options.dbName = 'admin';
255255

256-
return executeOperation(this.s.db, this.s.db.removeUser.bind(this.s.db), [
256+
return executeOperation(this.s.db.s.topology, this.s.db.removeUser.bind(this.s.db), [
257257
username,
258258
options,
259259
callback
@@ -278,7 +278,7 @@ Admin.prototype.validateCollection = function(collectionName, options, callback)
278278
options = args.length ? args.shift() : {};
279279
options = options || {};
280280

281-
return executeOperation(this.s.db, validateCollection, [this, collectionName, options, callback]);
281+
return executeOperation(this.s.db.s.topology, validateCollection, [this, collectionName, options, callback]);
282282
};
283283

284284
var validateCollection = function(self, collectionName, options, callback) {
@@ -324,7 +324,7 @@ Admin.prototype.listDatabases = function(options, callback) {
324324

325325
var cmd = { listDatabases: 1 };
326326
if (options.nameOnly) cmd.nameOnly = Number(cmd.nameOnly);
327-
return executeOperation(this.s.db, this.s.db.executeDbAdminCommand.bind(this.s.db), [
327+
return executeOperation(this.s.db.s.topology, this.s.db.executeDbAdminCommand.bind(this.s.db), [
328328
cmd,
329329
options,
330330
callback
@@ -343,7 +343,7 @@ define.classMethod('listDatabases', { callback: true, promise: true });
343343
*/
344344
Admin.prototype.replSetGetStatus = function(options, callback) {
345345
if (typeof options === 'function') (callback = options), (options = {});
346-
return executeOperation(this.s.db, replSetGetStatus, [this, options, callback]);
346+
return executeOperation(this.s.db.s.topology, replSetGetStatus, [this, options, callback]);
347347
};
348348

349349
var replSetGetStatus = function(self, options, callback) {

lib/bulk/ordered.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ OrderedBulkOperation.prototype.execute = function(_writeConcern, callback) {
588588
: this.s.promiseLibrary.reject(emptyBatchError);
589589
}
590590

591-
return executeOperation(this, executeCommands, [this, callback]);
591+
return executeOperation(this.s.topology, executeCommands, [this, callback]);
592592
};
593593

594594
define.classMethod('execute', { callback: true, promise: false });

lib/bulk/unordered.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ UnorderedBulkOperation.prototype.execute = function(_writeConcern, callback) {
602602
: this.s.promiseLibrary.reject(emptyBatchError);
603603
}
604604

605-
return executeOperation(this, executeBatches, [this, callback]);
605+
return executeOperation(this.s.topology, executeBatches, [this, callback]);
606606
};
607607

608608
define.classMethod('execute', { callback: true, promise: false });

0 commit comments

Comments
 (0)