mirror of https://github.com/mongodb/mongo
SERVER-109431: Apply more strict eslint checks on shell code (#40632)
GitOrigin-RevId: 3990cbfe7cba7229604fcca010e91a30a1010cca
This commit is contained in:
parent
86dc5fd42e
commit
bcc71d744a
|
|
@ -379,8 +379,20 @@ export default [
|
|||
// Shell-specific: extra strict!
|
||||
files: ["jstests/core/js/**", "jstests/noPassthrough/shell/**", "src/mongo/shell/**"],
|
||||
rules: {
|
||||
"no-var": 2,
|
||||
"logical-assignment-operators": 2,
|
||||
"no-extra-bind": 2,
|
||||
"no-irregular-whitespace": 2,
|
||||
"no-loss-of-precision": 2,
|
||||
"no-unneeded-ternary": 2,
|
||||
"no-unused-vars": [2, {args: "none", caughtErrors: "none"}],
|
||||
"no-useless-call": 2,
|
||||
"no-useless-escape": 2,
|
||||
"no-var": 2,
|
||||
"object-shorthand": 2,
|
||||
"prefer-object-has-own": 2,
|
||||
"prefer-object-spread": 2,
|
||||
"prefer-rest-params": 2,
|
||||
"prefer-spread": 2,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ function failNextCommand(db, command) {
|
|||
data: {
|
||||
closeConnection: true,
|
||||
failCommands: [command],
|
||||
threadName: threadName,
|
||||
threadName,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ function inspectCommandForSessionId(func, {shouldIncludeId, expectedId, differen
|
|||
|
||||
Mongo.prototype.runCommand = function runCommandSpy(dbName, cmdObj, options) {
|
||||
cmdObjSeen = cmdObj;
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
return mongoRunCommandOriginal.apply(this, arguments);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -368,26 +368,26 @@ describe("tojson", function () {
|
|||
|
||||
describe("Strings to escape", function () {
|
||||
it("serializes strings that needs escaping", function () {
|
||||
const stringThatNeedsEscaping = 'ho\"la';
|
||||
const stringThatNeedsEscaping = 'ho"la';
|
||||
|
||||
assert.eq('\"ho\\\"la\"', JSON.stringify(stringThatNeedsEscaping));
|
||||
assert.eq(tojson(stringThatNeedsEscaping), '\"ho\\\"la\"');
|
||||
assert.eq(toJsonForLog(stringThatNeedsEscaping), '\"ho\\\"la\"');
|
||||
assert.eq('"ho\\"la"', JSON.stringify(stringThatNeedsEscaping));
|
||||
assert.eq(tojson(stringThatNeedsEscaping), '"ho\\"la"');
|
||||
assert.eq(toJsonForLog(stringThatNeedsEscaping), '"ho\\"la"');
|
||||
|
||||
const obj = {quotes: stringThatNeedsEscaping};
|
||||
assert.eq(tojson(obj), '{ "quotes" : "ho\\\"la" }');
|
||||
assert.eq(tojson(obj), '{ "quotes" : "ho\\"la" }');
|
||||
});
|
||||
|
||||
it("serializes strings in errors", function () {
|
||||
const stringThatNeedsEscaping = 'ho\"la';
|
||||
const stringThatNeedsEscaping = 'ho"la';
|
||||
|
||||
assert.eq("{}", JSON.stringify(new Error(stringThatNeedsEscaping)));
|
||||
assert.eq(tojson(new Error(stringThatNeedsEscaping)), 'new Error(\"ho\\\"la\")');
|
||||
assert.eq(toJsonForLog(new Error(stringThatNeedsEscaping)), '{"$error":"ho\\\"la"}');
|
||||
assert.eq(tojson(new Error(stringThatNeedsEscaping)), 'new Error("ho\\"la")');
|
||||
assert.eq(toJsonForLog(new Error(stringThatNeedsEscaping)), '{"$error":"ho\\"la"}');
|
||||
|
||||
assert.eq("{}", JSON.stringify(new SyntaxError(stringThatNeedsEscaping)));
|
||||
assert.eq(tojson(new SyntaxError(stringThatNeedsEscaping)), 'new SyntaxError(\"ho\\\"la\")');
|
||||
assert.eq(toJsonForLog(new SyntaxError(stringThatNeedsEscaping)), '{"$error":"ho\\\"la"}');
|
||||
assert.eq(tojson(new SyntaxError(stringThatNeedsEscaping)), 'new SyntaxError("ho\\"la")');
|
||||
assert.eq(toJsonForLog(new SyntaxError(stringThatNeedsEscaping)), '{"$error":"ho\\"la"}');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@
|
|||
let fn = (val) => {
|
||||
return Promise.resolve(val);
|
||||
};
|
||||
Object.assign({}, await fn(42));
|
||||
({...(await fn(42))});
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ function testCommandCanBeRetried(func, expected = true) {
|
|||
|
||||
Mongo.prototype.runCommand = function runCommandSpy(dbName, cmdObj, options) {
|
||||
cmdObjSeen = cmdObj;
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
return mongoRunCommandOriginal.apply(this, arguments);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ function runTests({withSession}) {
|
|||
|
||||
Mongo.prototype.runCommand = function runCommandSpy(dbName, cmdObj, options) {
|
||||
cmdObjSeen = cmdObj;
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
return mongoRunCommandOriginal.apply(this, arguments);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ function testCommandGossipedWithClusterTime(func, expectedClusterTime) {
|
|||
|
||||
Mongo.prototype.runCommand = function runCommandSpy(dbName, cmdObj, options) {
|
||||
cmdObjSeen = cmdObj;
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
return mongoRunCommandOriginal.apply(this, arguments);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
let checkShell = function (retCode) {
|
||||
let args = ["mongo", "--nodb", "--eval", "quit(" + retCode + ");"];
|
||||
|
||||
let actualRetCode = _runMongoProgram.apply(null, args);
|
||||
let actualRetCode = _runMongoProgram(...args);
|
||||
assert.eq(retCode, actualRetCode);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ function testCommandIsRetried(testFn, assertFn) {
|
|||
cmdObjsSeen.push(cmdObj);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
return mongoRunCommandOriginal.apply(this, arguments);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ function runShellScript(uri, cmdArgs, insertShouldHaveTxnNumber, shellFn) {
|
|||
assert(!cmdObjSeen.hasOwnProperty("txnNumber"), "insert sent with txnNumber unexpectedly");
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
return mongoRunCommandOriginal.apply(this, arguments);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function runMongoShellWithRetryWritesEnabled(func) {
|
|||
const jsCode = "(" + func.toString() + ")()";
|
||||
args.push("--eval", jsCode);
|
||||
|
||||
const exitCode = runMongoProgram.apply(null, args);
|
||||
const exitCode = runMongoProgram(...args);
|
||||
assert.eq(0, exitCode, "Encountered an error in the other mongo shell");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -915,7 +915,7 @@ function assertThrowsHelper(func, params) {
|
|||
);
|
||||
}
|
||||
|
||||
return {error: error, res: res};
|
||||
return {error, res};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -937,9 +937,9 @@ function assertThrowsHelper(func, params) {
|
|||
assert.throws = function (func, params, msg, attr) {
|
||||
_validateAssertionMessage(msg, attr);
|
||||
|
||||
// Use .apply() instead of calling the function directly with explicit arguments to
|
||||
// preserve the length of the `arguments` object.
|
||||
const {error} = assertThrowsHelper.apply(null, arguments);
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
const {error} = assertThrowsHelper(...arguments);
|
||||
|
||||
if (!error) {
|
||||
_doassert(msg, "did not throw exception", attr);
|
||||
|
|
@ -1007,9 +1007,9 @@ assert.throwsWithCode = function (func, expectedCode, params, msg, attr) {
|
|||
assert.doesNotThrow = function (func, params, msg, attr) {
|
||||
_validateAssertionMessage(msg, attr);
|
||||
|
||||
// Use .apply() instead of calling the function directly with explicit arguments to
|
||||
// preserve the length of the `arguments` object.
|
||||
const {error, res} = assertThrowsHelper.apply(null, arguments);
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
const {error, res} = assertThrowsHelper(...arguments);
|
||||
|
||||
if (error) {
|
||||
const {code, message} = error;
|
||||
|
|
@ -1165,7 +1165,7 @@ function _assertCommandWorked(res, msg, {ignoreWriteErrors, ignoreWriteConcernEr
|
|||
if (_isWriteResultType(res)) {
|
||||
// These can only contain write errors, not command errors.
|
||||
if (!ignoreWriteErrors) {
|
||||
assert.writeOK(res, msg, {ignoreWriteConcernErrors: ignoreWriteConcernErrors});
|
||||
assert.writeOK(res, msg, {ignoreWriteConcernErrors});
|
||||
}
|
||||
} else if (res instanceof WriteCommandError || res instanceof Error) {
|
||||
// A WriteCommandError implies ok:0.
|
||||
|
|
@ -1177,8 +1177,8 @@ function _assertCommandWorked(res, msg, {ignoreWriteErrors, ignoreWriteConcernEr
|
|||
// response.
|
||||
if (
|
||||
!_rawReplyOkAndNoWriteErrors(res, {
|
||||
ignoreWriteErrors: ignoreWriteErrors,
|
||||
ignoreWriteConcernErrors: ignoreWriteConcernErrors,
|
||||
ignoreWriteErrors,
|
||||
ignoreWriteConcernErrors,
|
||||
})
|
||||
) {
|
||||
_runHangAnalyzerForSpecificFailureTypes(res);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ function MongoBridge(options) {
|
|||
return new MongoBridge(options);
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
options ||= {};
|
||||
if (!options.hasOwnProperty("dest")) {
|
||||
throw new Error('Missing required field "dest"');
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ function MongoBridge(options) {
|
|||
}
|
||||
});
|
||||
|
||||
let pid = _startMongoProgram.apply(null, args);
|
||||
let pid = _startMongoProgram(...args);
|
||||
|
||||
/**
|
||||
* Initializes the mongo shell's connections to the mongobridge process. Throws an error if the
|
||||
|
|
@ -110,7 +110,7 @@ function MongoBridge(options) {
|
|||
// we define it here for consistency.
|
||||
Object.defineProperty(userConn, "name", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
get() {
|
||||
return this.host;
|
||||
},
|
||||
});
|
||||
|
|
@ -231,7 +231,7 @@ function MongoBridge(options) {
|
|||
bridges.forEach((bridge) => {
|
||||
let res = runBridgeCommand(controlConn, "delayMessagesFrom", {
|
||||
host: bridge.dest,
|
||||
delay: delay,
|
||||
delay,
|
||||
});
|
||||
assert.commandWorked(
|
||||
res,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ const WRITE_CONCERN_FAILED = 64;
|
|||
let defineReadOnlyProperty = function (self, name, value) {
|
||||
Object.defineProperty(self, name, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
get() {
|
||||
return value;
|
||||
},
|
||||
});
|
||||
|
|
@ -30,6 +30,7 @@ let defineReadOnlyProperty = function (self, name, value) {
|
|||
function WriteConcern(wValue, wTimeout, jValue) {
|
||||
if (!(this instanceof WriteConcern)) {
|
||||
let writeConcern = Object.create(WriteConcern.prototype);
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
WriteConcern.apply(writeConcern, arguments);
|
||||
return writeConcern;
|
||||
}
|
||||
|
|
@ -266,7 +267,7 @@ function BulkWriteResult(bulkResult, singleBatchType, writeConcern) {
|
|||
}
|
||||
}
|
||||
|
||||
return new WriteConcernError({errmsg: errmsg, code: WRITE_CONCERN_FAILED});
|
||||
return new WriteConcernError({errmsg, code: WRITE_CONCERN_FAILED});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -340,6 +341,7 @@ function BulkWriteError(bulkResult, singleBatchType, writeConcern, message) {
|
|||
this.message = message || "unknown bulk write error";
|
||||
|
||||
// Bulk errors are basically bulk results with additional error information
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
BulkWriteResult.apply(this, arguments);
|
||||
|
||||
// Override some particular methods
|
||||
|
|
@ -522,7 +524,7 @@ let Bulk = function (collection, ordered) {
|
|||
let defineBatchTypeCounter = function (self, name, type) {
|
||||
Object.defineProperty(self, name, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
get() {
|
||||
let counter = 0;
|
||||
|
||||
for (let i = 0; i < batches.length; i++) {
|
||||
|
|
@ -643,11 +645,11 @@ let Bulk = function (collection, ordered) {
|
|||
//
|
||||
// Find based operations
|
||||
const findOperations = {
|
||||
update: function (updateDocument) {
|
||||
update(updateDocument) {
|
||||
// Set the top value for the update 0 = multi true, 1 = multi false
|
||||
let upsert = typeof currentOp.upsert == "boolean" ? currentOp.upsert : false;
|
||||
// Establish the update command
|
||||
let document = {q: currentOp.selector, u: updateDocument, multi: true, upsert: upsert};
|
||||
let document = {q: currentOp.selector, u: updateDocument, multi: true, upsert};
|
||||
|
||||
// Copy over the hint, if we have one.
|
||||
if (currentOp.hasOwnProperty("hint")) {
|
||||
|
|
@ -670,11 +672,11 @@ let Bulk = function (collection, ordered) {
|
|||
return addToOperationsList(UPDATE, document);
|
||||
},
|
||||
|
||||
updateOne: function (updateDocument) {
|
||||
updateOne(updateDocument) {
|
||||
// Set the top value for the update 0 = multi true, 1 = multi false
|
||||
let upsert = typeof currentOp.upsert == "boolean" ? currentOp.upsert : false;
|
||||
// Establish the update command
|
||||
let document = {q: currentOp.selector, u: updateDocument, multi: false, upsert: upsert};
|
||||
let document = {q: currentOp.selector, u: updateDocument, multi: false, upsert};
|
||||
|
||||
// Copy over the sort, if we have one.
|
||||
if (currentOp.hasOwnProperty("sort")) {
|
||||
|
|
@ -702,7 +704,7 @@ let Bulk = function (collection, ordered) {
|
|||
return addToOperationsList(UPDATE, document);
|
||||
},
|
||||
|
||||
replaceOne: function (updateDocument) {
|
||||
replaceOne(updateDocument) {
|
||||
// Cannot use pipeline-style updates in a replacement operation.
|
||||
if (Array.isArray(updateDocument)) {
|
||||
throw new Error("Cannot use pipeline-style updates in a replacement operation");
|
||||
|
|
@ -710,23 +712,23 @@ let Bulk = function (collection, ordered) {
|
|||
findOperations.updateOne(updateDocument);
|
||||
},
|
||||
|
||||
upsert: function () {
|
||||
upsert() {
|
||||
currentOp.upsert = true;
|
||||
// Return the findOperations
|
||||
return findOperations;
|
||||
},
|
||||
|
||||
sort: function (sort) {
|
||||
sort(sort) {
|
||||
currentOp.sort = sort;
|
||||
return findOperations;
|
||||
},
|
||||
|
||||
hint: function (hint) {
|
||||
hint(hint) {
|
||||
currentOp.hint = hint;
|
||||
return findOperations;
|
||||
},
|
||||
|
||||
removeOne: function () {
|
||||
removeOne() {
|
||||
// Establish the removeOne command
|
||||
let document = {q: currentOp.selector, limit: 1};
|
||||
|
||||
|
|
@ -741,7 +743,7 @@ let Bulk = function (collection, ordered) {
|
|||
return addToOperationsList(REMOVE, document);
|
||||
},
|
||||
|
||||
remove: function () {
|
||||
remove() {
|
||||
// Establish the remove command
|
||||
let document = {q: currentOp.selector, limit: 0};
|
||||
|
||||
|
|
@ -756,12 +758,12 @@ let Bulk = function (collection, ordered) {
|
|||
return addToOperationsList(REMOVE, document);
|
||||
},
|
||||
|
||||
collation: function (collationSpec) {
|
||||
collation(collationSpec) {
|
||||
currentOp.collation = collationSpec;
|
||||
return findOperations;
|
||||
},
|
||||
|
||||
arrayFilters: function (filters) {
|
||||
arrayFilters(filters) {
|
||||
currentOp.arrayFilters = filters;
|
||||
return findOperations;
|
||||
},
|
||||
|
|
@ -772,7 +774,7 @@ let Bulk = function (collection, ordered) {
|
|||
this.find = function (selector) {
|
||||
if (selector == undefined) throw Error("find() requires query criteria");
|
||||
// Save a current selector
|
||||
currentOp = {selector: selector};
|
||||
currentOp = {selector};
|
||||
|
||||
// Return the find Operations
|
||||
return findOperations;
|
||||
|
|
@ -857,7 +859,7 @@ let Bulk = function (collection, ordered) {
|
|||
|
||||
// Generate the right update
|
||||
if (batch.batchType == UPDATE) {
|
||||
cmd = {update: coll.getName(), updates: batch.operations, ordered: ordered};
|
||||
cmd = {update: coll.getName(), updates: batch.operations, ordered};
|
||||
} else if (batch.batchType == INSERT) {
|
||||
let transformedInserts = [];
|
||||
batch.operations.forEach(function (insertDoc) {
|
||||
|
|
@ -865,9 +867,9 @@ let Bulk = function (collection, ordered) {
|
|||
});
|
||||
batch.operations = transformedInserts;
|
||||
|
||||
cmd = {insert: coll.getName(), documents: batch.operations, ordered: ordered};
|
||||
cmd = {insert: coll.getName(), documents: batch.operations, ordered};
|
||||
} else if (batch.batchType == REMOVE) {
|
||||
cmd = {delete: coll.getName(), deletes: batch.operations, ordered: ordered};
|
||||
cmd = {delete: coll.getName(), deletes: batch.operations, ordered};
|
||||
}
|
||||
|
||||
// If we have a write concern
|
||||
|
|
@ -981,7 +983,7 @@ let Bulk = function (collection, ordered) {
|
|||
|
||||
let explainBatch = batches[0];
|
||||
let writeCmd = buildBatchCmd(explainBatch);
|
||||
return {"explain": writeCmd, "verbosity": verbosity};
|
||||
return {"explain": writeCmd, verbosity};
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -170,8 +170,8 @@ function checkContainsOnceJsonStringMatch(connOrFile, id, attrName, msg) {
|
|||
}
|
||||
|
||||
for (let logMsg of logMessages) {
|
||||
if (logMsg.search(`\"id\":${id},`) != -1) {
|
||||
if (logMsg.search(`\"${attrName}\":\"?[^\"|\\\"]*` + msg) != -1) {
|
||||
if (logMsg.search(`"id":${id},`) != -1) {
|
||||
if (logMsg.search(`"${attrName}":"?[^"|\\"]*` + msg) != -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -498,21 +498,21 @@ function compareLogs(obj, id, severity, context, attrsDict, isRelaxed = false) {
|
|||
}
|
||||
|
||||
export const checkLog = {
|
||||
getGlobalLog: getGlobalLog,
|
||||
getLogMessage: getLogMessage,
|
||||
checkContainsOnce: checkContainsOnce,
|
||||
checkContainsOnceJson: checkContainsOnceJson,
|
||||
checkContainsWithCountJson: checkContainsWithCountJson,
|
||||
checkContainsWithAtLeastCountJson: checkContainsWithAtLeastCountJson,
|
||||
checkContainsOnceJsonStringMatch: checkContainsOnceJsonStringMatch,
|
||||
compareLogs: compareLogs,
|
||||
contains: contains,
|
||||
containsLog: containsLog,
|
||||
containsJson: containsJson,
|
||||
containsRelaxedJson: containsRelaxedJson,
|
||||
containsWithCount: containsWithCount,
|
||||
containsWithAtLeastCount: containsWithAtLeastCount,
|
||||
formatAsLogLine: formatAsLogLine,
|
||||
formatAsJsonLogLine: formatAsJsonLogLine,
|
||||
getFilteredLogMessages: getFilteredLogMessages,
|
||||
getGlobalLog,
|
||||
getLogMessage,
|
||||
checkContainsOnce,
|
||||
checkContainsOnceJson,
|
||||
checkContainsWithCountJson,
|
||||
checkContainsWithAtLeastCountJson,
|
||||
checkContainsOnceJsonStringMatch,
|
||||
compareLogs,
|
||||
contains,
|
||||
containsLog,
|
||||
containsJson,
|
||||
containsRelaxedJson,
|
||||
containsWithCount,
|
||||
containsWithAtLeastCount,
|
||||
formatAsLogLine,
|
||||
formatAsJsonLogLine,
|
||||
getFilteredLogMessages,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -481,7 +481,7 @@ DBCollection.prototype._parseRemove = function (t, justOne) {
|
|||
}
|
||||
|
||||
// Normalize "justOne" to a bool.
|
||||
justOne = justOne ? true : false;
|
||||
justOne = !!justOne;
|
||||
|
||||
// Handle write concern.
|
||||
if (!wc) {
|
||||
|
|
@ -489,12 +489,12 @@ DBCollection.prototype._parseRemove = function (t, justOne) {
|
|||
}
|
||||
|
||||
return {
|
||||
"query": query,
|
||||
"justOne": justOne,
|
||||
"wc": wc,
|
||||
"collation": collation,
|
||||
query,
|
||||
justOne,
|
||||
wc,
|
||||
collation,
|
||||
"let": letParams,
|
||||
"rawData": rawData,
|
||||
rawData,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -587,24 +587,24 @@ DBCollection.prototype._parseUpdate = function (query, updateSpec, upsert, multi
|
|||
}
|
||||
|
||||
// Normalize 'upsert' and 'multi' to booleans.
|
||||
upsert = upsert ? true : false;
|
||||
multi = multi ? true : false;
|
||||
upsert = !!upsert;
|
||||
multi = !!multi;
|
||||
|
||||
if (!wc) {
|
||||
wc = this.getWriteConcern();
|
||||
}
|
||||
|
||||
return {
|
||||
"query": query,
|
||||
"updateSpec": updateSpec,
|
||||
"hint": hint,
|
||||
"upsert": upsert,
|
||||
"multi": multi,
|
||||
"wc": wc,
|
||||
"collation": collation,
|
||||
"arrayFilters": arrayFilters,
|
||||
query,
|
||||
updateSpec,
|
||||
hint,
|
||||
upsert,
|
||||
multi,
|
||||
wc,
|
||||
collation,
|
||||
arrayFilters,
|
||||
"let": letParams,
|
||||
"rawData": rawData,
|
||||
rawData,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -772,7 +772,7 @@ DBCollection.prototype.createIndexes = function (keys, options, commitQuorum, cm
|
|||
return this._db.runCommand({
|
||||
createIndexes: this.getName(),
|
||||
indexes: indexSpecs,
|
||||
commitQuorum: commitQuorum,
|
||||
commitQuorum,
|
||||
...cmdArgs,
|
||||
});
|
||||
};
|
||||
|
|
@ -782,7 +782,7 @@ DBCollection.prototype.reIndex = function () {
|
|||
};
|
||||
|
||||
DBCollection.prototype.dropIndexes = function (indexNames, cmdArgs) {
|
||||
indexNames = indexNames || "*";
|
||||
indexNames ||= "*";
|
||||
let res = this._db.runCommand({dropIndexes: this.getName(), index: indexNames, ...cmdArgs});
|
||||
assert(res, "no result from dropIndex result");
|
||||
if (res.ok) return res;
|
||||
|
|
@ -793,7 +793,7 @@ DBCollection.prototype.dropIndexes = function (indexNames, cmdArgs) {
|
|||
};
|
||||
|
||||
DBCollection.prototype.drop = function (options = {}) {
|
||||
const cmdObj = Object.assign({drop: this.getName()}, options);
|
||||
const cmdObj = {drop: this.getName(), ...options};
|
||||
const ret = this._db.runCommand(cmdObj);
|
||||
if (!ret.ok) {
|
||||
if (ret.errmsg == "ns not found") return false;
|
||||
|
|
@ -850,7 +850,7 @@ DBCollection.prototype.renameCollection = function (newName, dropTarget) {
|
|||
return this._db._adminCommand({
|
||||
renameCollection: this._fullName,
|
||||
to: this._db._name + "." + newName,
|
||||
dropTarget: dropTarget,
|
||||
dropTarget,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -963,7 +963,7 @@ DBCollection.prototype.dropIndex = function (index) {
|
|||
throw new Error("To drop indexes in the collection using '*', use db.collection.dropIndexes()");
|
||||
}
|
||||
|
||||
let res = this._dbCommand("dropIndexes", {index: index});
|
||||
let res = this._dbCommand("dropIndexes", {index});
|
||||
return res;
|
||||
};
|
||||
|
||||
|
|
@ -977,9 +977,9 @@ DBCollection.prototype._hiddenIndex = function (index, hidden) {
|
|||
// 'Array'.
|
||||
let indexField = {};
|
||||
if (typeof index == "string") {
|
||||
indexField = {name: index, hidden: hidden};
|
||||
indexField = {name: index, hidden};
|
||||
} else if (typeof index == "object") {
|
||||
indexField = {keyPattern: index, hidden: hidden};
|
||||
indexField = {keyPattern: index, hidden};
|
||||
} else {
|
||||
throw new Error("Index must be either the index name or the index specification document");
|
||||
}
|
||||
|
|
@ -1020,7 +1020,7 @@ DBCollection.prototype.stats = function (args) {
|
|||
throw new Error("Cannot filter indexDetails on both indexDetailsKey and " + "indexDetailsName");
|
||||
}
|
||||
// collStats can run on a secondary, so we need to apply readPreference
|
||||
let res = this._db.runReadCommand({collStats: this._shortName, scale: scale});
|
||||
let res = this._db.runReadCommand({collStats: this._shortName, scale});
|
||||
if (!res.ok) {
|
||||
return res;
|
||||
}
|
||||
|
|
@ -1111,7 +1111,7 @@ DBCollection.prototype.exists = function () {
|
|||
|
||||
DBCollection.prototype.isCapped = function () {
|
||||
const m = this.getMetadata();
|
||||
return m && m.options && m.options.capped ? true : false;
|
||||
return !!(m && m.options && m.options.capped);
|
||||
};
|
||||
|
||||
DBCollection.prototype.getUUID = function () {
|
||||
|
|
@ -1128,13 +1128,14 @@ DBCollection.prototype.getUUID = function () {
|
|||
DBCollection.prototype.aggregate = function (pipeline, aggregateOptions) {
|
||||
if (!(pipeline instanceof Array)) {
|
||||
// Support legacy varargs form. Also handles db.foo.aggregate().
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
pipeline = Array.from(arguments);
|
||||
aggregateOptions = {};
|
||||
} else if (aggregateOptions === undefined) {
|
||||
aggregateOptions = {};
|
||||
}
|
||||
|
||||
const cmdObj = this._makeCommand("aggregate", {pipeline: pipeline});
|
||||
const cmdObj = this._makeCommand("aggregate", {pipeline});
|
||||
|
||||
return this._db._runAggregate(cmdObj, aggregateOptions);
|
||||
};
|
||||
|
|
@ -1151,7 +1152,7 @@ DBCollection.prototype.convertToSingleObject = function (valueField) {
|
|||
* @param optional object of optional fields;
|
||||
*/
|
||||
DBCollection.prototype.mapReduce = function (map, reduce, optionsOrOutString) {
|
||||
let c = {mapreduce: this._shortName, map: map, reduce: reduce};
|
||||
let c = {mapreduce: this._shortName, map, reduce};
|
||||
assert(optionsOrOutString, "need to supply an optionsOrOutString");
|
||||
|
||||
if (typeof optionsOrOutString == "string") c["out"] = optionsOrOutString;
|
||||
|
|
@ -1341,7 +1342,7 @@ DBCollection.prototype.getSplitKeysForChunks = function (chunkSize) {
|
|||
let host = shardDoc.host;
|
||||
let sconn = new Mongo(host);
|
||||
|
||||
let chunks = config.chunks.find({_id: sh._collRE(this), shard: shard}).toArray();
|
||||
let chunks = config.chunks.find({_id: sh._collRE(this), shard}).toArray();
|
||||
|
||||
print("\nGetting split points for chunks on shard " + shard + " at " + host);
|
||||
|
||||
|
|
@ -1492,10 +1493,10 @@ DBCollection.prototype.getSecondaryOk = function () {
|
|||
return this._db.getSecondaryOk();
|
||||
};
|
||||
|
||||
DBCollection.prototype.getQueryOptions = function () {
|
||||
DBCollection.prototype.getQueryOptions = function (...args) {
|
||||
// inherit this method from DB but use apply so
|
||||
// that secondaryOk will be set if is overridden on this DBCollection
|
||||
return this._db.getQueryOptions.apply(this, arguments);
|
||||
return this._db.getQueryOptions.apply(this, args);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1565,7 +1566,7 @@ DBCollection.prototype.enableAutoMerger = function () {
|
|||
*
|
||||
*/
|
||||
DBCollection.prototype.count = function (query, options) {
|
||||
const cmd = Object.assign({count: this.getName(), query: this._massageObject(query || {})}, options);
|
||||
const cmd = {count: this.getName(), query: this._massageObject(query || {}), ...options};
|
||||
if (cmd.readConcern) {
|
||||
cmd.readConcern = {level: cmd.readConcern};
|
||||
}
|
||||
|
|
@ -1595,7 +1596,7 @@ DBCollection.prototype.count = function (query, options) {
|
|||
DBCollection.prototype.countDocuments = function (query, options) {
|
||||
"use strict";
|
||||
let pipeline = [{"$match": query}];
|
||||
options = options || {};
|
||||
options ||= {};
|
||||
assert.eq(typeof options, "object", "'options' argument must be an object");
|
||||
|
||||
if (options.skip) {
|
||||
|
|
@ -1646,7 +1647,7 @@ DBCollection.prototype.countDocuments = function (query, options) {
|
|||
DBCollection.prototype.estimatedDocumentCount = function (options) {
|
||||
"use strict";
|
||||
let cmd = {count: this.getName()};
|
||||
options = options || {};
|
||||
options ||= {};
|
||||
assert.eq(typeof options, "object", "'options' argument must be an object");
|
||||
|
||||
if (options.maxTimeMS) {
|
||||
|
|
@ -1725,12 +1726,12 @@ DBCollection.prototype._distinct = function (keyString, query) {
|
|||
};
|
||||
|
||||
DBCollection.prototype.latencyStats = function (options) {
|
||||
options = options || {};
|
||||
options ||= {};
|
||||
return this.aggregate([{$collStats: {latencyStats: options}}]);
|
||||
};
|
||||
|
||||
DBCollection.prototype.watch = function (pipeline, options) {
|
||||
pipeline = pipeline || [];
|
||||
pipeline ||= [];
|
||||
assert(pipeline instanceof Array, "'pipeline' argument must be an array");
|
||||
const [changeStreamStage, aggOptions] = this.getMongo()._extractChangeStreamOptions(options);
|
||||
return this.aggregate([changeStreamStage, ...pipeline], aggOptions);
|
||||
|
|
@ -1844,7 +1845,7 @@ PlanCache.prototype._parseQueryShape = function (query, projection, sort, collat
|
|||
}
|
||||
|
||||
let shape = {
|
||||
query: query,
|
||||
query,
|
||||
projection: projection == undefined ? {} : projection,
|
||||
sort: sort == undefined ? {} : sort,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ DBCollection.prototype.bulkWrite = function (operations, options) {
|
|||
let writeConcern = this._createWriteConcern(opts);
|
||||
|
||||
// Result
|
||||
let result = {acknowledged: writeConcern && writeConcern.w == 0 ? false : true};
|
||||
let result = {acknowledged: !(writeConcern && writeConcern.w == 0)};
|
||||
|
||||
// Use bulk operation API already in the shell
|
||||
let bulkOp = opts.ordered ? this.initializeOrderedBulkOp() : this.initializeUnorderedBulkOp();
|
||||
|
|
@ -266,7 +266,7 @@ DBCollection.prototype.insertOne = function (document, options) {
|
|||
let writeConcern = this._createWriteConcern(opts);
|
||||
|
||||
// Result
|
||||
let result = {acknowledged: writeConcern && writeConcern.w == 0 ? false : true};
|
||||
let result = {acknowledged: !(writeConcern && writeConcern.w == 0)};
|
||||
|
||||
// Use bulk operation API already in the shell
|
||||
let bulk = this.initializeOrderedBulkOp();
|
||||
|
|
@ -328,7 +328,7 @@ DBCollection.prototype.insertMany = function (documents, options) {
|
|||
let writeConcern = this._createWriteConcern(opts);
|
||||
|
||||
// Result
|
||||
let result = {acknowledged: writeConcern && writeConcern.w == 0 ? false : true};
|
||||
let result = {acknowledged: !(writeConcern && writeConcern.w == 0)};
|
||||
|
||||
// Use bulk operation API already in the shell
|
||||
let bulk = opts.ordered ? this.initializeOrderedBulkOp() : this.initializeUnorderedBulkOp();
|
||||
|
|
@ -374,7 +374,7 @@ DBCollection.prototype.deleteOne = function (filter, options) {
|
|||
let writeConcern = this._createWriteConcern(opts);
|
||||
|
||||
// Result
|
||||
let result = {acknowledged: writeConcern && writeConcern.w == 0 ? false : true};
|
||||
let result = {acknowledged: !(writeConcern && writeConcern.w == 0)};
|
||||
|
||||
// Use bulk operation API already in the shell
|
||||
let bulk = this.initializeOrderedBulkOp();
|
||||
|
|
@ -436,7 +436,7 @@ DBCollection.prototype.deleteMany = function (filter, options) {
|
|||
let writeConcern = this._createWriteConcern(opts);
|
||||
|
||||
// Result
|
||||
let result = {acknowledged: writeConcern && writeConcern.w == 0 ? false : true};
|
||||
let result = {acknowledged: !(writeConcern && writeConcern.w == 0)};
|
||||
|
||||
// Use bulk operation API already in the shell
|
||||
let bulk = this.initializeOrderedBulkOp();
|
||||
|
|
@ -512,7 +512,7 @@ DBCollection.prototype.replaceOne = function (filter, replacement, options) {
|
|||
let writeConcern = this._createWriteConcern(opts);
|
||||
|
||||
// Result
|
||||
let result = {acknowledged: writeConcern && writeConcern.w == 0 ? false : true};
|
||||
let result = {acknowledged: !(writeConcern && writeConcern.w == 0)};
|
||||
|
||||
// Use bulk operation API already in the shell
|
||||
let bulk = this.initializeOrderedBulkOp();
|
||||
|
|
@ -602,7 +602,7 @@ DBCollection.prototype.updateOne = function (filter, update, options) {
|
|||
let writeConcern = this._createWriteConcern(opts);
|
||||
|
||||
// Result
|
||||
let result = {acknowledged: writeConcern && writeConcern.w == 0 ? false : true};
|
||||
let result = {acknowledged: !(writeConcern && writeConcern.w == 0)};
|
||||
|
||||
// Use bulk operation API already in the shell
|
||||
let bulk = this.initializeOrderedBulkOp();
|
||||
|
|
@ -699,7 +699,7 @@ DBCollection.prototype.updateMany = function (filter, update, options) {
|
|||
let writeConcern = this._createWriteConcern(opts);
|
||||
|
||||
// Result
|
||||
let result = {acknowledged: writeConcern && writeConcern.w == 0 ? false : true};
|
||||
let result = {acknowledged: !(writeConcern && writeConcern.w == 0)};
|
||||
|
||||
// Use bulk operation API already in the shell
|
||||
let bulk = this.initializeOrderedBulkOp();
|
||||
|
|
@ -927,7 +927,7 @@ DBCollection.prototype.findOneAndUpdate = function (filter, update, options) {
|
|||
}
|
||||
|
||||
// Set up the command
|
||||
let cmd = {query: filter || {}, update: update};
|
||||
let cmd = {query: filter || {}, update};
|
||||
if (opts.sort) {
|
||||
cmd.sort = opts.sort;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class CollInfos {
|
|||
const collInfoRaw = this.collInfosRes.find((elem) => elem.name === collName);
|
||||
if (collInfoRaw) {
|
||||
collInfo = {
|
||||
ns: ns,
|
||||
ns,
|
||||
host: this.conn.host,
|
||||
UUID: collInfoRaw.info.uuid,
|
||||
count: coll.find().itcount(),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const DB =
|
|||
* @param {String} message optional message for server to log at rotation time
|
||||
*/
|
||||
DB.prototype.rotateCertificates = function (message) {
|
||||
return this._adminCommand({rotateCertificates: 1, message: message});
|
||||
return this._adminCommand({rotateCertificates: 1, message});
|
||||
};
|
||||
|
||||
DB.prototype.getMongo = function () {
|
||||
|
|
@ -234,7 +234,7 @@ DB.prototype._helloOrLegacyHello = function (args) {
|
|||
};
|
||||
|
||||
DB.prototype._runCommandWithoutApiStrict = function (command) {
|
||||
let commandWithoutApiStrict = Object.assign({}, command);
|
||||
let commandWithoutApiStrict = {...command};
|
||||
if (this.getMongo().getApiParameters().strict) {
|
||||
// Permit this command invocation, even if it's not in the requested API version.
|
||||
commandWithoutApiStrict["apiStrict"] = false;
|
||||
|
|
@ -307,7 +307,7 @@ DB.prototype._runAggregate = function (cmdObj, aggregateOptions) {
|
|||
|
||||
DB.prototype.aggregate = function (pipeline, aggregateOptions) {
|
||||
assert(pipeline instanceof Array, "pipeline argument must be an array");
|
||||
const cmdObj = this._mergeCommandOptions("aggregate", {pipeline: pipeline});
|
||||
const cmdObj = this._mergeCommandOptions("aggregate", {pipeline});
|
||||
|
||||
return this._runAggregate(cmdObj, aggregateOptions || {});
|
||||
};
|
||||
|
|
@ -440,7 +440,7 @@ DB.prototype.shutdownServer = function (opts) {
|
|||
}
|
||||
|
||||
let cmd = {"shutdown": 1};
|
||||
opts = opts || {};
|
||||
opts ||= {};
|
||||
for (let o in opts) {
|
||||
cmd[o] = opts[o];
|
||||
}
|
||||
|
|
@ -610,12 +610,12 @@ DB.prototype.setProfilingLevel = function (level, options) {
|
|||
* @return result of your function, or null if error
|
||||
*
|
||||
*/
|
||||
DB.prototype.eval = function (jsfunction) {
|
||||
DB.prototype.eval = function (jsfunction, ...args) {
|
||||
print("WARNING: db.eval is deprecated");
|
||||
|
||||
let cmd = {$eval: jsfunction};
|
||||
if (arguments.length > 1) {
|
||||
cmd.args = Array.from(arguments).slice(1);
|
||||
if (args.length > 0) {
|
||||
cmd.args = args;
|
||||
}
|
||||
|
||||
let res = this._dbCommand(cmd);
|
||||
|
|
@ -702,12 +702,12 @@ DB.prototype._getCollectionInfosCommand = function (
|
|||
authorizedCollections = false,
|
||||
options = {},
|
||||
) {
|
||||
filter = filter || {};
|
||||
filter ||= {};
|
||||
const cmd = {
|
||||
listCollections: 1,
|
||||
filter: filter,
|
||||
nameOnly: nameOnly,
|
||||
authorizedCollections: authorizedCollections,
|
||||
filter,
|
||||
nameOnly,
|
||||
authorizedCollections,
|
||||
};
|
||||
|
||||
const res = this.runCommand(Object.merge(cmd, options));
|
||||
|
|
@ -821,7 +821,7 @@ DB.prototype.currentOp = function (arg) {
|
|||
const results = this.currentOpCursor(arg).toArray();
|
||||
let res = {"inprog": results.length > 0 ? results : [], "ok": 1};
|
||||
Object.defineProperty(res, "fsyncLock", {
|
||||
get: function () {
|
||||
get() {
|
||||
throw Error(
|
||||
"fsyncLock is no longer included in the currentOp shell helper, run db.runCommand({currentOp: 1}) instead.",
|
||||
);
|
||||
|
|
@ -871,7 +871,7 @@ DB.prototype.currentOpCursor = function (arg) {
|
|||
|
||||
DB.prototype.killOp = function (op) {
|
||||
if (!op) throw Error("no opNum to kill specified");
|
||||
return this.adminCommand({"killOp": 1, "op": op});
|
||||
return this.adminCommand({"killOp": 1, op});
|
||||
};
|
||||
DB.prototype.killOP = DB.prototype.killOp;
|
||||
|
||||
|
|
@ -1141,7 +1141,7 @@ DB.autocomplete = function (obj) {
|
|||
let colls = obj._getCollectionNamesInternal(isInteractive() ? {maxTimeMS: 1000} : {});
|
||||
let ret = [];
|
||||
for (let i = 0; i < colls.length; i++) {
|
||||
if (colls[i].match(/^[a-zA-Z0-9_.\$]+$/)) ret.push(colls[i]);
|
||||
if (colls[i].match(/^[a-zA-Z0-9_.$]+$/)) ret.push(colls[i]);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
|
@ -1391,16 +1391,16 @@ DB.prototype._getDefaultAuthenticationMechanism = function (username, database)
|
|||
|
||||
DB.prototype._defaultGssapiServiceName = null;
|
||||
|
||||
DB.prototype._authOrThrow = function () {
|
||||
DB.prototype._authOrThrow = function (...args) {
|
||||
let params;
|
||||
if (arguments.length == 2) {
|
||||
params = {user: arguments[0], pwd: arguments[1]};
|
||||
} else if (arguments.length == 1) {
|
||||
if (typeof arguments[0] === "string") {
|
||||
if (args.length == 2) {
|
||||
params = {user: args[0], pwd: args[1]};
|
||||
} else if (args.length == 1) {
|
||||
if (typeof args[0] === "string") {
|
||||
let password = passwordPrompt();
|
||||
params = {user: arguments[0], pwd: password};
|
||||
} else if (typeof arguments[0] === "object") {
|
||||
params = Object.extend({}, arguments[0]);
|
||||
params = {user: args[0], pwd: password};
|
||||
} else if (typeof args[0] === "object") {
|
||||
params = Object.extend({}, args[0]);
|
||||
} else {
|
||||
throw Error("Single-argument form of auth expects a parameter object");
|
||||
}
|
||||
|
|
@ -1431,9 +1431,9 @@ DB.prototype._authOrThrow = function () {
|
|||
return good;
|
||||
};
|
||||
|
||||
DB.prototype.auth = function () {
|
||||
DB.prototype.auth = function (...args) {
|
||||
try {
|
||||
this._authOrThrow.apply(this, arguments);
|
||||
this._authOrThrow(...args);
|
||||
} catch (ex) {
|
||||
print(ex);
|
||||
return 0;
|
||||
|
|
@ -1444,7 +1444,7 @@ DB.prototype.auth = function () {
|
|||
DB.prototype.grantRolesToUser = function (username, roles, writeConcern) {
|
||||
let cmdObj = {
|
||||
grantRolesToUser: username,
|
||||
roles: roles,
|
||||
roles,
|
||||
writeConcern: writeConcern ? writeConcern : _defaultWriteConcern,
|
||||
};
|
||||
let res = this.runCommand(cmdObj);
|
||||
|
|
@ -1456,7 +1456,7 @@ DB.prototype.grantRolesToUser = function (username, roles, writeConcern) {
|
|||
DB.prototype.revokeRolesFromUser = function (username, roles, writeConcern) {
|
||||
let cmdObj = {
|
||||
revokeRolesFromUser: username,
|
||||
roles: roles,
|
||||
roles,
|
||||
writeConcern: writeConcern ? writeConcern : _defaultWriteConcern,
|
||||
};
|
||||
let res = this.runCommand(cmdObj);
|
||||
|
|
@ -1557,7 +1557,7 @@ DB.prototype.dropAllRoles = function (writeConcern) {
|
|||
DB.prototype.grantRolesToRole = function (rolename, roles, writeConcern) {
|
||||
let cmdObj = {
|
||||
grantRolesToRole: rolename,
|
||||
roles: roles,
|
||||
roles,
|
||||
writeConcern: writeConcern ? writeConcern : _defaultWriteConcern,
|
||||
};
|
||||
let res = this.runCommand(cmdObj);
|
||||
|
|
@ -1569,7 +1569,7 @@ DB.prototype.grantRolesToRole = function (rolename, roles, writeConcern) {
|
|||
DB.prototype.revokeRolesFromRole = function (rolename, roles, writeConcern) {
|
||||
let cmdObj = {
|
||||
revokeRolesFromRole: rolename,
|
||||
roles: roles,
|
||||
roles,
|
||||
writeConcern: writeConcern ? writeConcern : _defaultWriteConcern,
|
||||
};
|
||||
let res = this.runCommand(cmdObj);
|
||||
|
|
@ -1581,7 +1581,7 @@ DB.prototype.revokeRolesFromRole = function (rolename, roles, writeConcern) {
|
|||
DB.prototype.grantPrivilegesToRole = function (rolename, privileges, writeConcern) {
|
||||
let cmdObj = {
|
||||
grantPrivilegesToRole: rolename,
|
||||
privileges: privileges,
|
||||
privileges,
|
||||
writeConcern: writeConcern ? writeConcern : _defaultWriteConcern,
|
||||
};
|
||||
let res = this.runCommand(cmdObj);
|
||||
|
|
@ -1593,7 +1593,7 @@ DB.prototype.grantPrivilegesToRole = function (rolename, privileges, writeConcer
|
|||
DB.prototype.revokePrivilegesFromRole = function (rolename, privileges, writeConcern) {
|
||||
let cmdObj = {
|
||||
revokePrivilegesFromRole: rolename,
|
||||
privileges: privileges,
|
||||
privileges,
|
||||
writeConcern: writeConcern ? writeConcern : _defaultWriteConcern,
|
||||
};
|
||||
let res = this.runCommand(cmdObj);
|
||||
|
|
@ -1660,7 +1660,7 @@ DB.prototype.setLogLevel = function (logLevel, component) {
|
|||
};
|
||||
|
||||
DB.prototype.watch = function (pipeline, options) {
|
||||
pipeline = pipeline || [];
|
||||
pipeline ||= [];
|
||||
assert(pipeline instanceof Array, "'pipeline' argument must be an array");
|
||||
|
||||
const [changeStreamStage, aggOptions] = this.getMongo()._extractChangeStreamOptions(options);
|
||||
|
|
@ -1689,7 +1689,7 @@ DB.prototype.createEncryptedCollection = function (name, opts) {
|
|||
|
||||
const res = assert.commandWorked(this.createCollection(name, opts));
|
||||
|
||||
const cis = this.getCollectionInfos({"name": name});
|
||||
const cis = this.getCollectionInfos({name});
|
||||
assert.eq(cis.length, 1, `Expected to find one collection named '${name}'`);
|
||||
|
||||
const ci = cis[0];
|
||||
|
|
@ -1707,7 +1707,7 @@ DB.prototype.createEncryptedCollection = function (name, opts) {
|
|||
};
|
||||
|
||||
DB.prototype.dropEncryptedCollection = function (name) {
|
||||
const ci = globalThis.db.getCollectionInfos({name: name})[0];
|
||||
const ci = globalThis.db.getCollectionInfos({name})[0];
|
||||
if (ci == undefined) {
|
||||
throw `Encrypted Collection '${name}' not found`;
|
||||
}
|
||||
|
|
@ -1750,40 +1750,40 @@ DB.prototype.getServerBuildInfo = function () {
|
|||
};
|
||||
|
||||
return {
|
||||
rawData: function () {
|
||||
rawData() {
|
||||
return buildInfo;
|
||||
},
|
||||
|
||||
getVersion: function () {
|
||||
getVersion() {
|
||||
return buildInfo.version;
|
||||
},
|
||||
|
||||
getBits: function () {
|
||||
getBits() {
|
||||
return buildInfo.bits;
|
||||
},
|
||||
|
||||
isOptimizationsEnabled: function () {
|
||||
isOptimizationsEnabled() {
|
||||
const optimizationsMatch = /(\s|^)-O2(\s|$)/.exec(buildInfo["buildEnvironment"]["ccflags"]);
|
||||
return Boolean(optimizationsMatch);
|
||||
},
|
||||
|
||||
isAddressSanitizerActive: function () {
|
||||
isAddressSanitizerActive() {
|
||||
return _sanitizeMatch("address");
|
||||
},
|
||||
|
||||
isLeakSanitizerActive: function () {
|
||||
isLeakSanitizerActive() {
|
||||
return _sanitizeMatch("leak");
|
||||
},
|
||||
|
||||
isThreadSanitizerActive: function () {
|
||||
isThreadSanitizerActive() {
|
||||
return _sanitizeMatch("thread");
|
||||
},
|
||||
|
||||
isUndefinedBehaviorSanitizerActive: function () {
|
||||
isUndefinedBehaviorSanitizerActive() {
|
||||
return _sanitizeMatch("undefined");
|
||||
},
|
||||
|
||||
isDebug: function () {
|
||||
isDebug() {
|
||||
return buildInfo.debug;
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class DBExplainQuery {
|
|||
*/
|
||||
#createDelegationFunc(name) {
|
||||
return (...args) => {
|
||||
this._query[name].apply(this._query, args);
|
||||
this._query[name](...args);
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ let throwOrReturn = function (explainResult) {
|
|||
};
|
||||
|
||||
let buildExplainCmd = function (innerCmd, verbosity) {
|
||||
let explainCmd = {"explain": innerCmd, "verbosity": verbosity};
|
||||
let explainCmd = {"explain": innerCmd, verbosity};
|
||||
// If "maxTimeMS" is set on innerCmd, it needs to be propagated to the top-level
|
||||
// of explainCmd so that it has the intended effect.
|
||||
if (innerCmd.hasOwnProperty("maxTimeMS")) {
|
||||
|
|
@ -103,6 +103,7 @@ function Explainable(collection, verbosity) {
|
|||
this.aggregate = function (pipeline, extraOpts) {
|
||||
if (!(pipeline instanceof Array)) {
|
||||
// Support legacy varargs form. (Also handles db.foo.aggregate())
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
pipeline = Array.from(arguments);
|
||||
extraOpts = {};
|
||||
}
|
||||
|
|
@ -122,7 +123,7 @@ function Explainable(collection, verbosity) {
|
|||
extraOptsCopy = Object.extend(extraOptsCopy, {cursor: {}});
|
||||
}
|
||||
|
||||
let aggCmd = Object.extend({"aggregate": this._collection.getName(), "pipeline": pipeline}, extraOptsCopy);
|
||||
let aggCmd = Object.extend({"aggregate": this._collection.getName(), pipeline}, extraOptsCopy);
|
||||
let explainCmd = buildExplainCmd(aggCmd, this._verbosity);
|
||||
let explainResult = this._collection.runReadCommand(explainCmd);
|
||||
return throwOrReturn(explainResult);
|
||||
|
|
@ -139,8 +140,8 @@ function Explainable(collection, verbosity) {
|
|||
* the DBExplainQuery abstraction in order to construct the proper explain command to send
|
||||
* to the server.
|
||||
*/
|
||||
this.find = function () {
|
||||
let cursor = this._collection.find.apply(this._collection, arguments);
|
||||
this.find = function (...args) {
|
||||
let cursor = this._collection.find(...args);
|
||||
return new DBExplainQuery(cursor, this._verbosity);
|
||||
};
|
||||
|
||||
|
|
@ -176,8 +177,8 @@ function Explainable(collection, verbosity) {
|
|||
return throwOrReturn(explainResult);
|
||||
};
|
||||
|
||||
this.remove = function () {
|
||||
let parsed = this._collection._parseRemove.apply(this._collection, arguments);
|
||||
this.remove = function (...args) {
|
||||
let parsed = this._collection._parseRemove(...args);
|
||||
let query = parsed.query;
|
||||
let justOne = parsed.justOne;
|
||||
let collation = parsed.collation;
|
||||
|
|
@ -206,8 +207,8 @@ function Explainable(collection, verbosity) {
|
|||
return throwOrReturn(explainResult);
|
||||
};
|
||||
|
||||
this.update = function () {
|
||||
let parsed = this._collection._parseUpdate.apply(this._collection, arguments);
|
||||
this.update = function (...args) {
|
||||
let parsed = this._collection._parseUpdate(...args);
|
||||
let query = parsed.query;
|
||||
let updateSpec = parsed.updateSpec;
|
||||
let upsert = parsed.upsert;
|
||||
|
|
@ -255,7 +256,7 @@ function Explainable(collection, verbosity) {
|
|||
this.mapReduce = function (map, reduce, optionsObjOrOutString) {
|
||||
assert(optionsObjOrOutString, "Must supply the 'optionsObjOrOutString ' argument");
|
||||
|
||||
const mapReduceCmd = {mapreduce: this._collection.getName(), map: map, reduce: reduce};
|
||||
const mapReduceCmd = {mapreduce: this._collection.getName(), map, reduce};
|
||||
|
||||
if (typeof optionsObjOrOutString == "string") mapReduceCmd["out"] = optionsObjOrOutString;
|
||||
else Object.extend(mapReduceCmd, optionsObjOrOutString);
|
||||
|
|
@ -700,8 +701,8 @@ Explain.sbeReformatExperimental(<explain>, <fieldsToKeep>)
|
|||
}
|
||||
|
||||
const Explain = {
|
||||
help: help,
|
||||
sbeReformatExperimental: sbeReformatExperimental,
|
||||
help,
|
||||
sbeReformatExperimental,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class KeyVault {
|
|||
"updateDate": current,
|
||||
"status": NumberInt(0),
|
||||
"version": NumberLong(0),
|
||||
"masterKey": masterKey,
|
||||
masterKey,
|
||||
};
|
||||
|
||||
if (keyAltNames) {
|
||||
|
|
@ -163,12 +163,12 @@ class ClientEncryption {
|
|||
this.mongo = mongo;
|
||||
}
|
||||
|
||||
encrypt() {
|
||||
return this.mongo.encrypt.apply(this.mongo, arguments);
|
||||
encrypt(...args) {
|
||||
return this.mongo.encrypt(...args);
|
||||
}
|
||||
|
||||
decrypt() {
|
||||
return this.mongo.decrypt.apply(this.mongo, arguments);
|
||||
decrypt(...args) {
|
||||
return this.mongo.decrypt(...args);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -550,7 +550,7 @@ Mongo.prototype.waitForClusterTime = function waitForClusterTime(maxRetries = 10
|
|||
* stream stage specification and the options for the aggregate command, respectively.
|
||||
*/
|
||||
Mongo.prototype._extractChangeStreamOptions = function (options) {
|
||||
options = options || {};
|
||||
options ||= {};
|
||||
assert(options instanceof Object, "'options' argument must be an object");
|
||||
|
||||
let changeStreamOptions = {fullDocument: options.fullDocument || "default"};
|
||||
|
|
@ -622,7 +622,7 @@ Mongo.prototype._extractChangeStreamOptions = function (options) {
|
|||
};
|
||||
|
||||
Mongo.prototype.watch = function (pipeline, options) {
|
||||
pipeline = pipeline || [];
|
||||
pipeline ||= [];
|
||||
assert(pipeline instanceof Array, "'pipeline' argument must be an array");
|
||||
|
||||
const [changeStreamStage, aggOptions] = this._extractChangeStreamOptions(options);
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ DBQuery.prototype.maxTimeMS = function (maxTimeMS) {
|
|||
|
||||
DBQuery.prototype.readConcern = function (level, atClusterTime = undefined) {
|
||||
this._checkModify();
|
||||
let readConcernObj = atClusterTime ? {level: level, atClusterTime: atClusterTime} : {level: level};
|
||||
let readConcernObj = atClusterTime ? {level, atClusterTime} : {level};
|
||||
this._additionalCmdParams["readConcern"] = readConcernObj;
|
||||
return this;
|
||||
};
|
||||
|
|
@ -455,7 +455,7 @@ DBQuery.prototype.rawData = function (value) {
|
|||
* Returns 'this'.
|
||||
*/
|
||||
DBQuery.prototype.readPref = function (mode, tagSet) {
|
||||
let readPrefObj = {mode: mode};
|
||||
let readPrefObj = {mode};
|
||||
|
||||
if (tagSet) {
|
||||
readPrefObj.tags = tagSet;
|
||||
|
|
|
|||
|
|
@ -60,13 +60,13 @@ MongoRunner.getExtensionPath = function (shared_library_name) {
|
|||
return shared_library_name;
|
||||
};
|
||||
|
||||
MongoRunner.parsePort = function () {
|
||||
MongoRunner.parsePort = function (...args) {
|
||||
let port = "";
|
||||
const portKey = jsTestOptions().shellGRPC ? "--grpcPort" : "--port";
|
||||
|
||||
for (let i = 0; i < arguments.length; ++i) {
|
||||
if (arguments[i] == portKey) {
|
||||
port = arguments[i + 1];
|
||||
for (let i = 0; i < args.length; ++i) {
|
||||
if (args[i] == portKey) {
|
||||
port = args[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -324,7 +324,7 @@ MongoRunner.logicalOptions = {
|
|||
|
||||
MongoRunner.toRealPath = function (path, pathOpts) {
|
||||
// Replace all $pathOptions with actual values
|
||||
pathOpts = pathOpts || {};
|
||||
pathOpts ||= {};
|
||||
path = path.replace(/\$dataPath/g, MongoRunner.dataPath);
|
||||
path = path.replace(/\$dataDir/g, MongoRunner.dataDir);
|
||||
for (let key in pathOpts) {
|
||||
|
|
@ -542,7 +542,7 @@ MongoRunner.mongoOptions = function (opts) {
|
|||
}
|
||||
|
||||
// Create a new runId
|
||||
opts.runId = opts.runId || ObjectId();
|
||||
opts.runId ||= ObjectId();
|
||||
|
||||
if (opts.forgetPort) {
|
||||
delete opts.port;
|
||||
|
|
@ -563,7 +563,7 @@ MongoRunner.mongoOptions = function (opts) {
|
|||
// Default for waitForConnect is true
|
||||
opts.waitForConnect = waitForConnect == undefined || waitForConnect == null ? true : waitForConnect;
|
||||
|
||||
opts.port = opts.port || allocatePort();
|
||||
opts.port ||= allocatePort();
|
||||
|
||||
if (jsTestOptions().tlsMode && !opts.tlsMode) {
|
||||
opts.tlsMode = jsTestOptions().tlsMode;
|
||||
|
|
@ -581,7 +581,7 @@ MongoRunner.mongoOptions = function (opts) {
|
|||
const setParameters = jsTestOptions().setParameters || {};
|
||||
const tlsEnabled = (opts.tlsMode && opts.tlsMode != "disabled") || (opts.sslMode && opts.sslMode != "disabled");
|
||||
if (setParameters.featureFlagGRPC && tlsEnabled) {
|
||||
opts.grpcPort = opts.grpcPort || allocatePort();
|
||||
opts.grpcPort ||= allocatePort();
|
||||
grpcToMongoRpcPortMap[opts.grpcPort] = opts.port;
|
||||
}
|
||||
|
||||
|
|
@ -693,7 +693,7 @@ MongoRunner.mongodOptions = function (opts = {}) {
|
|||
|
||||
opts.pathOpts = Object.merge(opts.pathOpts, {dbpath: opts.dbpath});
|
||||
|
||||
opts.setParameter = opts.setParameter || {};
|
||||
opts.setParameter ||= {};
|
||||
if (jsTestOptions().enableTestCommands && typeof opts.setParameter !== "string") {
|
||||
if (
|
||||
jsTestOptions().setParameters &&
|
||||
|
|
@ -902,7 +902,7 @@ MongoRunner.runningChildPids = function () {
|
|||
* @see MongoRunner.arrOptions
|
||||
*/
|
||||
MongoRunner.runMongod = function (opts) {
|
||||
opts = opts || {};
|
||||
opts ||= {};
|
||||
let env = undefined;
|
||||
let useHostName = true;
|
||||
let runId = null;
|
||||
|
|
@ -972,7 +972,7 @@ MongoRunner.getMongosName = function (port, useHostName) {
|
|||
};
|
||||
|
||||
MongoRunner.runMongos = function (opts) {
|
||||
opts = opts || {};
|
||||
opts ||= {};
|
||||
|
||||
let env = undefined;
|
||||
let useHostName = false;
|
||||
|
|
@ -1084,7 +1084,7 @@ let stopMongoProgram = function (conn, signal, opts, waitpid) {
|
|||
}
|
||||
|
||||
signal = parseInt(signal) || SIGTERM;
|
||||
opts = opts || {};
|
||||
opts ||= {};
|
||||
waitpid = waitpid === undefined ? true : waitpid;
|
||||
|
||||
// If we are executing an unclean shutdown, we want to avoid checking collection counts during
|
||||
|
|
@ -1564,21 +1564,21 @@ MongoRunner._startWithArgs = function (argArray, env, waitForConnect, waitForCon
|
|||
}
|
||||
|
||||
if (env === undefined) {
|
||||
pid = _startMongoProgram.apply(null, argArray);
|
||||
pid = _startMongoProgram(...argArray);
|
||||
} else {
|
||||
pid = _startMongoProgram({args: argArray, env: env});
|
||||
pid = _startMongoProgram({args: argArray, env});
|
||||
}
|
||||
|
||||
delete serverExitCodeMap[port];
|
||||
if (!waitForConnect) {
|
||||
print("Skip waiting to connect to node with pid=" + pid + ", port=" + port);
|
||||
return {
|
||||
pid: pid,
|
||||
port: port,
|
||||
pid,
|
||||
port,
|
||||
};
|
||||
}
|
||||
|
||||
return MongoRunner.awaitConnection({pid: pid, port: port, waitTimeoutMS: waitForConnectTimeoutMS});
|
||||
return MongoRunner.awaitConnection({pid, port, waitTimeoutMS: waitForConnectTimeoutMS});
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1589,15 +1589,14 @@ MongoRunner._startWithArgs = function (argArray, env, waitForConnect, waitForCon
|
|||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function startMongoProgram() {
|
||||
let port = MongoRunner.parsePort.apply(null, arguments);
|
||||
function startMongoProgram(...args) {
|
||||
let port = MongoRunner.parsePort(...args);
|
||||
|
||||
// Enable test commands.
|
||||
// TODO: Make this work better with multi-version testing so that we can support
|
||||
// enabling this on 2.4 when testing 2.6
|
||||
let args = Array.from(arguments);
|
||||
args = appendSetParameterArgs(args);
|
||||
let pid = _startMongoProgram.apply(null, args);
|
||||
let pid = _startMongoProgram(...args);
|
||||
|
||||
let m;
|
||||
assert.soon(
|
||||
|
|
@ -1685,8 +1684,8 @@ function _getMongoProgramArguments(args) {
|
|||
return args;
|
||||
}
|
||||
|
||||
function runMongoProgram() {
|
||||
return _runMongoProgram.apply(null, _getMongoProgramArguments(arguments));
|
||||
function runMongoProgram(...args) {
|
||||
return _runMongoProgram(..._getMongoProgramArguments(args));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1694,8 +1693,8 @@ function runMongoProgram() {
|
|||
* program name, and subsequent arguments to this function are passed as
|
||||
* command line arguments to the program. Returns pid of the spawned program.
|
||||
*/
|
||||
function startMongoProgramNoConnect() {
|
||||
return _startMongoProgram.apply(null, _getMongoProgramArguments(arguments));
|
||||
function startMongoProgramNoConnect(...args) {
|
||||
return _startMongoProgram(..._getMongoProgramArguments(args));
|
||||
}
|
||||
|
||||
export {MongoRunner, runMongoProgram, startMongoProgram, startMongoProgramNoConnect};
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ ToolTest.prototype.startDB = function (coll) {
|
|||
|
||||
Object.extend(options, this.options);
|
||||
|
||||
this.m = startMongoProgram.apply(null, MongoRunner.arrOptions("mongod", options));
|
||||
this.m = startMongoProgram(...MongoRunner.arrOptions("mongod", options));
|
||||
this.db = this.m.getDB(this.baseName);
|
||||
if (coll) return this.db.getCollection(coll);
|
||||
return this.db;
|
||||
|
|
@ -33,31 +33,6 @@ ToolTest.prototype.stop = function () {
|
|||
print("*** " + this.name + " completed successfully ***");
|
||||
};
|
||||
|
||||
ToolTest.prototype.runTool = function () {
|
||||
let a = ["mongo" + arguments[0]];
|
||||
|
||||
let hasdbpath = false;
|
||||
let hasDialTimeout = false;
|
||||
|
||||
for (let i = 1; i < arguments.length; i++) {
|
||||
a.push(arguments[i]);
|
||||
if (arguments[i] === "--dbpath") hasdbpath = true;
|
||||
if (arguments[i] === "--dialTimeout") hasDialTimeout = true;
|
||||
}
|
||||
|
||||
if (!hasdbpath) {
|
||||
a.push("--host");
|
||||
a.push("127.0.0.1:" + this.port);
|
||||
}
|
||||
|
||||
if (!hasDialTimeout) {
|
||||
a.push("--dialTimeout");
|
||||
a.push("30");
|
||||
}
|
||||
|
||||
return runMongoProgram.apply(null, a);
|
||||
};
|
||||
|
||||
// Defer initializing these variables until the first call, as TestData attributes may be
|
||||
// initialized as part of the --eval argument (e.g. by resmoke.py), which will not be evaluated
|
||||
// until after this has loaded.
|
||||
|
|
@ -70,8 +45,8 @@ let nextPort;
|
|||
function allocatePort() {
|
||||
// The default port was chosen in an attempt to have a large number of unassigned ports that
|
||||
// are also outside the ephemeral port range.
|
||||
nextPort = nextPort || jsTestOptions().minPort || 20000;
|
||||
maxPort = maxPort || jsTestOptions().maxPort || Math.pow(2, 16) - 1;
|
||||
nextPort ||= jsTestOptions().minPort || 20000;
|
||||
maxPort ||= jsTestOptions().maxPort || Math.pow(2, 16) - 1;
|
||||
|
||||
if (nextPort === maxPort) {
|
||||
throw new Error("Exceeded maximum port range in allocatePort()");
|
||||
|
|
@ -152,7 +127,7 @@ function startParallelShell(jsCode, port, noConnect, ...optionArgs) {
|
|||
args.push(...optionArgs);
|
||||
args.push("--eval", jsCode);
|
||||
|
||||
let pid = startMongoProgramNoConnect.apply(null, args);
|
||||
let pid = startMongoProgramNoConnect(...args);
|
||||
parallelShellPids.push(pid);
|
||||
|
||||
// Returns a function that when called waits for the parallel shell to exit and returns the exit
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ function SessionAwareClient(client) {
|
|||
};
|
||||
|
||||
function gossipClusterTime(cmdObj, clusterTime) {
|
||||
cmdObj = Object.assign({}, cmdObj);
|
||||
cmdObj = {...cmdObj};
|
||||
|
||||
if (!cmdObj.hasOwnProperty("$clusterTime")) {
|
||||
cmdObj.$clusterTime = clusterTime;
|
||||
|
|
@ -213,19 +213,19 @@ function SessionAwareClient(client) {
|
|||
return cmdObj;
|
||||
}
|
||||
|
||||
cmdObj = Object.assign({}, cmdObj);
|
||||
cmdObj = {...cmdObj};
|
||||
let cmdName = Object.keys(cmdObj)[0];
|
||||
|
||||
// Explain read concerns are on the inner command.
|
||||
let cmdObjUnwrapped = cmdObj;
|
||||
if (cmdName === "explain") {
|
||||
cmdObj[cmdName] = Object.assign({}, cmdObj[cmdName]);
|
||||
cmdObj[cmdName] = {...cmdObj[cmdName]};
|
||||
cmdObjUnwrapped = cmdObj[cmdName];
|
||||
}
|
||||
|
||||
// Transaction read concerns are handled later in assignTxnInfo().
|
||||
const sessionReadConcern = driverSession.getOptions().getReadConcern();
|
||||
cmdObjUnwrapped.readConcern = Object.assign({}, sessionReadConcern, cmdObjUnwrapped.readConcern);
|
||||
cmdObjUnwrapped.readConcern = {...sessionReadConcern, ...cmdObjUnwrapped.readConcern};
|
||||
const readConcern = cmdObjUnwrapped.readConcern;
|
||||
|
||||
if (!readConcern.hasOwnProperty("afterClusterTime")) {
|
||||
|
|
@ -586,7 +586,7 @@ function ServerSession(client) {
|
|||
}
|
||||
|
||||
this.injectSessionId = function injectSessionId(cmdObj) {
|
||||
cmdObj = Object.assign({}, cmdObj);
|
||||
cmdObj = {...cmdObj};
|
||||
|
||||
if (!cmdObj.hasOwnProperty("lsid")) {
|
||||
if (isAcknowledged(cmdObj)) {
|
||||
|
|
@ -602,7 +602,7 @@ function ServerSession(client) {
|
|||
};
|
||||
|
||||
this.assignTransactionNumber = function assignTransactionNumber(cmdObj) {
|
||||
cmdObj = Object.assign({}, cmdObj);
|
||||
cmdObj = {...cmdObj};
|
||||
|
||||
if (!cmdObj.hasOwnProperty("txnNumber")) {
|
||||
this.handle.incrementTxnNumber();
|
||||
|
|
@ -631,7 +631,7 @@ function ServerSession(client) {
|
|||
setTxnState("inactive");
|
||||
throw new Error("Transactions are only supported on server versions 4.0 and greater.");
|
||||
}
|
||||
cmdObj = Object.assign({}, cmdObj);
|
||||
cmdObj = {...cmdObj};
|
||||
|
||||
const cmdName = Object.keys(cmdObj)[0];
|
||||
|
||||
|
|
@ -651,7 +651,7 @@ function ServerSession(client) {
|
|||
cmdObj.startTransaction = true;
|
||||
if (_txnOptions.getTxnReadConcern() !== undefined) {
|
||||
// Override the readConcern with the one specified during startTransaction.
|
||||
cmdObj.readConcern = Object.assign({}, cmdObj.readConcern, _txnOptions.getTxnReadConcern());
|
||||
cmdObj.readConcern = {...cmdObj.readConcern, ..._txnOptions.getTxnReadConcern()};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ Timestamp.prototype.toStringIncomparable = function () {
|
|||
Date.timeFunc = function (theFunc, numTimes = 1, ...args) {
|
||||
let start = new Date();
|
||||
for (let i = 0; i < numTimes; i++) {
|
||||
theFunc.apply(null, args);
|
||||
theFunc(...args);
|
||||
}
|
||||
|
||||
return new Date().getTime() - start.getTime();
|
||||
|
|
@ -569,7 +569,7 @@ BSONAwareMap.prototype._get = function (key) {
|
|||
return a[i];
|
||||
}
|
||||
}
|
||||
let o = {key: key, value: null};
|
||||
let o = {key, value: null};
|
||||
a.push(o);
|
||||
return o;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -68,9 +68,9 @@ function _getErrorWithCode(codeOrObj, message) {
|
|||
*/
|
||||
|
||||
function retryOnRetryableError(func, numRetries, sleepMs, additionalCodesToRetry) {
|
||||
numRetries = numRetries || 1;
|
||||
sleepMs = sleepMs || 1000;
|
||||
additionalCodesToRetry = additionalCodesToRetry || [];
|
||||
numRetries ||= 1;
|
||||
sleepMs ||= 1000;
|
||||
additionalCodesToRetry ||= [];
|
||||
|
||||
while (true) {
|
||||
if (numRetries % 10 === 0) {
|
||||
|
|
@ -99,8 +99,8 @@ function retryOnRetryableError(func, numRetries, sleepMs, additionalCodesToRetry
|
|||
* Returns the return value of the input call.
|
||||
*/
|
||||
function retryOnNetworkError(func, numRetries, sleepMs) {
|
||||
numRetries = numRetries || 1;
|
||||
sleepMs = sleepMs || 1000;
|
||||
numRetries ||= 1;
|
||||
sleepMs ||= 1000;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
|
|
@ -239,7 +239,7 @@ function friendlyEqual(a, b) {
|
|||
if (a == b) return true;
|
||||
|
||||
let clean = function (s) {
|
||||
s = s.replace(/NumberInt\((\-?\d+)\)/g, "$1");
|
||||
s = s.replace(/NumberInt\((-?\d+)\)/g, "$1");
|
||||
return s;
|
||||
};
|
||||
|
||||
|
|
@ -282,15 +282,15 @@ function compareOn(field) {
|
|||
};
|
||||
}
|
||||
|
||||
print.captureAllOutput = function (fn, args) {
|
||||
print.captureAllOutput = function (fn, ...args) {
|
||||
let res = {};
|
||||
res.output = [];
|
||||
let __orig_print = print;
|
||||
print = function () {
|
||||
Array.prototype.push.apply(res.output, Array.prototype.slice.call(arguments).join(" ").split("\n"));
|
||||
print = function (...args) {
|
||||
res.output.push(...args.join(" ").split("\n"));
|
||||
};
|
||||
try {
|
||||
res.result = fn.apply(undefined, args);
|
||||
res.result = fn(...args);
|
||||
} finally {
|
||||
// Stop capturing print() output
|
||||
print = __orig_print;
|
||||
|
|
@ -511,7 +511,7 @@ function jsTestLog(msg, attr, {severity = "I"} = {}) {
|
|||
"s": severity,
|
||||
"c": "js_test",
|
||||
"ctx": TestData?.testName || "-", // context (e.g., TestData.testName)
|
||||
"msg": msg, // message body
|
||||
msg, // message body
|
||||
};
|
||||
if (attr && typeof attr === "object" && Object.keys(attr).length > 0) {
|
||||
new_msg["attr"] = attr;
|
||||
|
|
@ -962,7 +962,7 @@ shellAutocomplete.showPrivate = false; // toggle to show (useful when working on
|
|||
|
||||
function shellHelper(command, rest, shouldPrint) {
|
||||
command = command.trim();
|
||||
let args = rest.trim().replace(/\s*;$/, "").split("\s+");
|
||||
let args = rest.trim().replace(/\s*;$/, "").split(/\s+/);
|
||||
|
||||
if (!shellHelper[command]) throw Error("no command [" + command + "]");
|
||||
|
||||
|
|
@ -1399,14 +1399,14 @@ let Random = (function () {
|
|||
}
|
||||
|
||||
return {
|
||||
genExp: genExp,
|
||||
genNormal: genNormal,
|
||||
isInitialized: isInitialized,
|
||||
rand: rand,
|
||||
randInt: randInt,
|
||||
setRandomSeed: setRandomSeed,
|
||||
setRandomFixtureSeed: setRandomFixtureSeed,
|
||||
srand: srand,
|
||||
genExp,
|
||||
genNormal,
|
||||
isInitialized,
|
||||
rand,
|
||||
randInt,
|
||||
setRandomSeed,
|
||||
setRandomFixtureSeed,
|
||||
srand,
|
||||
};
|
||||
})();
|
||||
|
||||
|
|
@ -1499,7 +1499,7 @@ function rs() {
|
|||
* replica set.
|
||||
*/
|
||||
function _awaitRSHostViaRSMonitor(hostAddr, desiredState, rsName, timeout) {
|
||||
timeout = timeout || 60 * 1000;
|
||||
timeout ||= 60 * 1000;
|
||||
|
||||
if (desiredState == undefined) {
|
||||
desiredState = {ok: true};
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ sh._writeBalancerStateDeprecated = function (onOrNot) {
|
|||
._getConfigDB()
|
||||
.settings.update(
|
||||
{_id: "balancer"},
|
||||
{$set: {stopped: onOrNot ? false : true}},
|
||||
{$set: {stopped: !onOrNot}},
|
||||
{upsert: true, writeConcern: {w: "majority"}},
|
||||
),
|
||||
);
|
||||
|
|
@ -181,7 +181,7 @@ sh.shardCollection = function (fullName, key, unique, options) {
|
|||
assert(key, "need a key");
|
||||
assert(typeof key == "object", "key needs to be an object");
|
||||
|
||||
let cmd = {shardCollection: fullName, key: key};
|
||||
let cmd = {shardCollection: fullName, key};
|
||||
if (unique) cmd.unique = true;
|
||||
if (options) {
|
||||
if (typeof options !== "object") {
|
||||
|
|
@ -195,17 +195,17 @@ sh.shardCollection = function (fullName, key, unique, options) {
|
|||
|
||||
sh.splitFind = function (fullName, find) {
|
||||
sh._checkFullName(fullName);
|
||||
return sh._adminCommand({split: fullName, find: find});
|
||||
return sh._adminCommand({split: fullName, find});
|
||||
};
|
||||
|
||||
sh.splitAt = function (fullName, middle) {
|
||||
sh._checkFullName(fullName);
|
||||
return sh._adminCommand({split: fullName, middle: middle});
|
||||
return sh._adminCommand({split: fullName, middle});
|
||||
};
|
||||
|
||||
sh.moveChunk = function (fullName, find, to) {
|
||||
sh._checkFullName(fullName);
|
||||
return sh._adminCommand({moveChunk: fullName, find: find, to: to});
|
||||
return sh._adminCommand({moveChunk: fullName, find, to});
|
||||
};
|
||||
|
||||
sh.setBalancerState = function (isOn) {
|
||||
|
|
@ -237,14 +237,14 @@ sh.isBalancerRunning = function (configDB) {
|
|||
};
|
||||
|
||||
sh.stopBalancer = function (timeoutMs, interval) {
|
||||
timeoutMs = timeoutMs || 60000;
|
||||
timeoutMs ||= 60000;
|
||||
|
||||
let result = globalThis.db.adminCommand({balancerStop: 1, maxTimeMS: timeoutMs});
|
||||
return assert.commandWorked(result);
|
||||
};
|
||||
|
||||
sh.startBalancer = function (timeoutMs, interval) {
|
||||
timeoutMs = timeoutMs || 60000;
|
||||
timeoutMs ||= 60000;
|
||||
|
||||
let result = globalThis.db.adminCommand({balancerStart: 1, maxTimeMS: timeoutMs});
|
||||
return assert.commandWorked(result);
|
||||
|
|
@ -365,7 +365,7 @@ sh.waitForPingChange = function (activePings, timeout, interval) {
|
|||
* round. If no round has been executed, throws an error.
|
||||
*/
|
||||
sh.awaitBalancerRound = function (timeout, interval) {
|
||||
timeout = timeout || 60000;
|
||||
timeout ||= 60000;
|
||||
|
||||
let initialStatus = sh._getBalancerStatus();
|
||||
let currentStatus;
|
||||
|
|
@ -418,8 +418,8 @@ sh.awaitCollectionBalance = function (coll, timeout, interval) {
|
|||
if (coll === undefined) {
|
||||
throw Error("Must specify collection");
|
||||
}
|
||||
timeout = timeout || 60000;
|
||||
interval = interval || 200;
|
||||
timeout ||= 60000;
|
||||
interval ||= 200;
|
||||
|
||||
const ns = coll.getFullName();
|
||||
const orphanDocsPipeline = [
|
||||
|
|
@ -619,15 +619,15 @@ sh.addTagRange = function (ns, min, max, tag) {
|
|||
let config = sh._getConfigDB();
|
||||
return assert.commandWorked(
|
||||
config.tags.update(
|
||||
{_id: {ns: ns, min: min}},
|
||||
{_id: {ns: ns, min: min}, ns: ns, min: min, max: max, tag: tag},
|
||||
{_id: {ns, min}},
|
||||
{_id: {ns, min}, ns, min, max, tag},
|
||||
{upsert: true, writeConcern: {w: "majority", wtimeout: 60000}},
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
sh.removeTagRange = function (ns, min, max) {
|
||||
return sh._getConfigDB().adminCommand({updateZoneKeyRange: ns, min: min, max: max, zone: null});
|
||||
return sh._getConfigDB().adminCommand({updateZoneKeyRange: ns, min, max, zone: null});
|
||||
};
|
||||
|
||||
sh.addShardToZone = function (shardName, zoneName) {
|
||||
|
|
@ -639,11 +639,11 @@ sh.removeShardFromZone = function (shardName, zoneName) {
|
|||
};
|
||||
|
||||
sh.updateZoneKeyRange = function (ns, min, max, zoneName) {
|
||||
return sh._getConfigDB().adminCommand({updateZoneKeyRange: ns, min: min, max: max, zone: zoneName});
|
||||
return sh._getConfigDB().adminCommand({updateZoneKeyRange: ns, min, max, zone: zoneName});
|
||||
};
|
||||
|
||||
sh.removeRangeFromZone = function (ns, min, max) {
|
||||
return sh._getConfigDB().adminCommand({updateZoneKeyRange: ns, min: min, max: max, zone: null});
|
||||
return sh._getConfigDB().adminCommand({updateZoneKeyRange: ns, min, max, zone: null});
|
||||
};
|
||||
|
||||
sh.getBalancerWindow = function (configDB) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue