diff options
author | Dianna Hohensee <dianna.hohensee@10gen.com> | 2018-08-27 13:06:38 -0400 |
---|---|---|
committer | Dianna Hohensee <dianna.hohensee@10gen.com> | 2018-08-29 16:47:09 -0400 |
commit | 4cb0742947dabee476c9979cae39c728a21568d5 (patch) | |
tree | 8ec6baacaab48a11b20eae4781f32be1bdad6ec2 /src/mongo/shell | |
parent | aa36a9e8ad8c98e828f1b53966672b368d973380 (diff) | |
download | mongo-4cb0742947dabee476c9979cae39c728a21568d5.tar.gz |
SERVER-36015 Remove references to system.namespaces and system.indexes
Diffstat (limited to 'src/mongo/shell')
-rw-r--r-- | src/mongo/shell/collection.js | 71 | ||||
-rw-r--r-- | src/mongo/shell/db.js | 56 |
2 files changed, 16 insertions, 111 deletions
diff --git a/src/mongo/shell/collection.js b/src/mongo/shell/collection.js index 55cafb2fac0..584136fa99e 100644 --- a/src/mongo/shell/collection.js +++ b/src/mongo/shell/collection.js @@ -641,27 +641,10 @@ DBCollection.prototype.createIndexes = function(keys, options) { indexSpecs[i] = this._indexSpec(keys[i], options); } - if (this.getMongo().writeMode() == "commands") { - for (var i = 0; i < indexSpecs.length; i++) { - delete (indexSpecs[i].ns); // ns is passed to the first element in the command. - } - return this._db.runCommand({createIndexes: this.getName(), indexes: indexSpecs}); - } else if (this.getMongo().writeMode() == "compatibility") { - // Use the downconversion machinery of the bulk api to do a safe write, report response as a - // command response - var result = this._db.getCollection("system.indexes").insert(indexSpecs, 0); - - if (result.hasWriteErrors() || result.hasWriteConcernError()) { - // Return the first error - var error = result.hasWriteErrors() ? result.getWriteErrors()[0] - : result.getWriteConcernError(); - return {ok: 0.0, code: error.code, errmsg: error.errmsg}; - } else { - return {ok: 1.0}; - } - } else { - this._db.getCollection("system.indexes").insert(indexSpecs, 0); + for (var i = 0; i < indexSpecs.length; i++) { + delete (indexSpecs[i].ns); // ns is passed to the first element in the command. } + return this._db.runCommand({createIndexes: this.getName(), indexes: indexSpecs}); }; DBCollection.prototype.ensureIndex = function(keys, options) { @@ -822,46 +805,21 @@ DBCollection.prototype.getShardVersion = function() { return this._db._adminCommand({getShardVersion: this._fullName}); }; -DBCollection.prototype._getIndexesSystemIndexes = function(filter) { - var si = this.getDB().getCollection("system.indexes"); - var query = {ns: this.getFullName()}; - if (filter) - query = Object.extend(query, filter); - return si.find(query).toArray(); -}; - -DBCollection.prototype._getIndexesCommand = function(filter) { +DBCollection.prototype.getIndexes = function(filter) { var res = this.runCommand("listIndexes", filter); if (!res.ok) { - if (res.code == 59) { - // command doesn't exist, old mongod - return null; - } - - if (res.code == 26) { - // NamespaceNotFound, for compatability, return [] + if (res.code == ErrorCodes.NamespaceNotFound) { + // For compatibility, return [] return []; } - if (res.errmsg && res.errmsg.startsWith("no such cmd")) { - return null; - } - throw _getErrorWithCode(res, "listIndexes failed: " + tojson(res)); } return new DBCommandCursor(this._db, res).toArray(); }; -DBCollection.prototype.getIndexes = function(filter) { - var res = this._getIndexesCommand(filter); - if (res) { - return res; - } - return this._getIndexesSystemIndexes(filter); -}; - DBCollection.prototype.getIndices = DBCollection.prototype.getIndexes; DBCollection.prototype.getIndexSpecs = DBCollection.prototype.getIndexes; @@ -881,16 +839,11 @@ DBCollection.prototype.hashAllDocs = function() { }; /** - * <p>Drop a specified index.</p> + * Drop a specified index. * - * <p> - * "index" is the name of the index in the system.indexes name field (run db.system.indexes.find() - *to - * see example data), or an object holding the key(s) used to create the index. - * For example: - * db.collectionName.dropIndex( "myIndexName" ); - * db.collectionName.dropIndex( { "indexKey" : 1 } ); - * </p> + * "index" is the name or key pattern of the index. For example: + * db.collectionName.dropIndex( "myIndexName" ); + * db.collectionName.dropIndex( { "indexKey" : 1 } ); * * @param {String} name or key object of index to delete. * @return A result object. result.ok will be true if successful. @@ -1032,10 +985,6 @@ DBCollection.prototype.exists = function() { return cursor.next(); } - if (res.errmsg && res.errmsg.startsWith("no such cmd")) { - return this._db.system.namespaces.findOne({name: this._fullName}); - } - throw _getErrorWithCode(res, "listCollections failed: " + tojson(res)); }; diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js index 9f6f497d5d1..d487497de36 100644 --- a/src/mongo/shell/db.js +++ b/src/mongo/shell/db.js @@ -858,39 +858,6 @@ var DB; return this.runCommand({getpreverror: 1}); }; - DB.prototype._getCollectionInfosSystemNamespaces = function(filter) { - var all = []; - - var dbNamePrefix = this._name + "."; - - // Create a shallow copy of 'filter' in case we modify its 'name' property. Also defaults - // 'filter' to {} if the parameter was not specified. - filter = Object.extend({}, filter); - if (typeof filter.name === "string") { - // Queries on the 'name' field need to qualify the namespace with the database name for - // consistency with the command variant. - filter.name = dbNamePrefix + filter.name; - } - - var c = this.getCollection("system.namespaces").find(filter); - while (c.hasNext()) { - var infoObj = c.next(); - - if (infoObj.name.indexOf("$") >= 0 && infoObj.name.indexOf(".oplog.$") < 0) - continue; - - // Remove the database name prefix from the collection info object. - infoObj.name = infoObj.name.substring(dbNamePrefix.length); - - all.push(infoObj); - } - - // Return list of objects sorted by collection name. - return all.sort(function(coll1, coll2) { - return coll1.name.localeCompare(coll2.name); - }); - }; - DB.prototype._getCollectionInfosCommand = function( filter, nameOnly = false, authorizedCollections = false) { filter = filter || {}; @@ -949,39 +916,28 @@ var DB; */ DB.prototype.getCollectionInfos = function( filter, nameOnly = false, authorizedCollections = false) { - let oldException; try { return this._getCollectionInfosCommand(filter, nameOnly, authorizedCollections); } catch (ex) { - if (ex.code !== ErrorCodes.Unauthorized && ex.code !== ErrorCodes.CommandNotFound && - !ex.message.startsWith("no such cmd")) { + if (ex.code !== ErrorCodes.Unauthorized) { // We cannot recover from this error, propagate it. throw ex; } - oldException = ex; - } - // We have failed to run listCollections. This may be due to the command not - // existing, or authorization failing. Try to query the system.namespaces collection. - try { - return this._getCollectionInfosSystemNamespaces(filter); - } catch (ex2) { - // Querying the system.namespaces collection has failed. We may be able to compute a - // set of *some* collections which exist and we have access to from our privileges. - // For this to work, the previous operations must have failed due to authorization, - // we must be attempting to recover the names of our own collections, + // We may be able to compute a set of *some* collections which exist and we have access + // to from our privileges. For this to work, the previous operation must have failed due + // to authorization, we must be attempting to recover the names of our own collections, // and no filter can have been provided. if (nameOnly && authorizedCollections && Object.getOwnPropertyNames(filter).length === 0 && - oldException.code === ErrorCodes.Unauthorized && - ex2.code == ErrorCodes.Unauthorized) { + ex.code === ErrorCodes.Unauthorized) { print( "Warning: unable to run listCollections, attempting to approximate collection names by parsing connectionStatus"); return this._getCollectionInfosFromPrivileges(); } - throw oldException; + throw ex; } }; |