summaryrefslogtreecommitdiff
path: root/src/mongo/shell/db.js
diff options
context:
space:
mode:
authorA. Jesse Jiryu Davis <jesse@mongodb.com>2019-04-19 13:52:12 -0400
committerA. Jesse Jiryu Davis <jesse@mongodb.com>2019-04-26 15:17:45 -0400
commitb6cc1fb89f8fbf92c66ef6274a1de1ad310b2fb1 (patch)
tree29ab701040440b3002ecd32c952993eb7b56821f /src/mongo/shell/db.js
parentfa23ce3476904d41f981a677aa4aba55deec4791 (diff)
downloadmongo-b6cc1fb89f8fbf92c66ef6274a1de1ad310b2fb1.tar.gz
SERVER-35638 Short timeout to autocomplete collection names
Also resolves SERVER-40736, test autocompletion of collection names for users without the listCollections permission.
Diffstat (limited to 'src/mongo/shell/db.js')
-rw-r--r--src/mongo/shell/db.js21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index d12e872e417..43123fd9361 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -816,14 +816,16 @@ var DB;
DB.prototype.getLastErrorCmd = DB.prototype.getLastErrorObj;
DB.prototype._getCollectionInfosCommand = function(
- filter, nameOnly = false, authorizedCollections = false) {
+ filter, nameOnly = false, authorizedCollections = false, options = {}) {
filter = filter || {};
- var res = this.runCommand({
+ const cmd = {
listCollections: 1,
filter: filter,
nameOnly: nameOnly,
authorizedCollections: authorizedCollections
- });
+ };
+
+ const res = this.runCommand(Object.merge(cmd, options));
if (!res.ok) {
throw _getErrorWithCode(res, "listCollections failed: " + tojson(res));
}
@@ -898,13 +900,17 @@ var DB;
}
};
+ DB.prototype._getCollectionNamesInternal = function(options) {
+ return this._getCollectionInfosCommand({}, true, true, options).map(function(infoObj) {
+ return infoObj.name;
+ });
+ };
+
/**
* Returns this database's list of collection names in sorted order.
*/
DB.prototype.getCollectionNames = function() {
- return this.getCollectionInfos({}, true, true).map(function(infoObj) {
- return infoObj.name;
- });
+ return this._getCollectionNamesInternal({});
};
DB.prototype.tojson = function() {
@@ -1249,7 +1255,8 @@ var DB;
};
DB.autocomplete = function(obj) {
- var colls = obj.getCollectionNames();
+ // Time out if a transaction or other op holds locks we need. Caller suppresses exceptions.
+ var colls = obj._getCollectionNamesInternal({maxTimeMS: 1000});
var ret = [];
for (var i = 0; i < colls.length; i++) {
if (colls[i].match(/^[a-zA-Z0-9_.\$]+$/))