0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00

shell should use the db's reIndex command

This commit is contained in:
Dwight 2010-01-29 14:58:10 -05:00
parent 8f21c738c1
commit b8f779a2a2
3 changed files with 46 additions and 44 deletions

View File

@ -495,7 +495,9 @@ namespace mongo {
/* assuming here that id index is not multikey: */
d->multiKeyIndexBits = 0;
assureSysIndexesEmptied(ns, idIndex);
anObjBuilder.append("msg", "non-_id indexes dropped for collection");
anObjBuilder.append("msg", mayDeleteIdIndex ?
"indexes dropped for collection" :
"non-_id indexes dropped for collection");
}
else {
// delete just one index

View File

@ -730,9 +730,12 @@ namespace mongo {
/* unindex all keys in all indexes for this record. */
static void unindexRecord(NamespaceDetails *d, Record *todelete, const DiskLoc& dl, bool noWarn = false) {
BSONObj obj(todelete);
int n = d->nIndexesBeingBuilt();
for ( int i = 0; i < n; i++ ) {
int n = d->nIndexes;
for ( int i = 0; i < n; i++ )
_unindexRecord(d->idx(i), obj, dl, !noWarn);
if( d->backgroundIndexBuildInProgress ) {
// always pass nowarn here, as this one may be missing for valid reasons as we are concurrently building it
_unindexRecord(d->idx(n), obj, dl, false);
}
}

View File

@ -35,6 +35,7 @@ DBCollection.prototype.help = function(){
print("\tdb.foo.dropIndex(name)");
print("\tdb.foo.dropIndexes()");
print("\tdb.foo.ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups");
print("\tdb.foo.reIndex()");
print("\tdb.foo.find( [query] , [fields]) - first parameter is an optional query filter. second parameter is optional set of fields to return.");
print("\t e.g. db.foo.find( { x : 77 } , { name : 1 , x : 1 } )");
print("\tdb.foo.find(...).count()");
@ -284,11 +285,7 @@ DBCollection.prototype.resetIndexCache = function(){
}
DBCollection.prototype.reIndex = function() {
var specs = this.getIndexSpecs();
this.dropIndexes();
for ( var i = 0; i < specs.length; ++i ){
this.ensureIndex( specs[i].key, [ specs[i].unique, specs[i].name ] );
}
return this._db.runCommand({ reIndex: this.getName() });
}
DBCollection.prototype.dropIndexes = function(){