summaryrefslogtreecommitdiff
path: root/src/mongo/shell/collection.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/shell/collection.js')
-rw-r--r--src/mongo/shell/collection.js71
1 files changed, 10 insertions, 61 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));
};