Skip to content

Instantly share code, notes, and snippets.

@piscis
Last active September 15, 2018 16:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save piscis/3b3df53241fdbb859c07 to your computer and use it in GitHub Desktop.
MongoDB: Drop all indexes on all collections in one database
db.getCollectionNames().forEach( function (d) {
db[d].dropIndexes();
});
db.tilezoom_source.chunks.ensureIndex( { files_id: 1, n: 1 }, { unique: true } );
db.tilezoom_artefacts.chunks.ensureIndex( { files_id: 1, n: 1 }, { unique: true } );
db.mosaic_artefact.chunks.ensureIndex( { files_id: 1, n: 1 }, { unique: true } );
db.mosaic_artefact_index.chunks.ensureIndex( { files_id: 1, n: 1 }, { unique: true } );
@dr-dimitru
Copy link

dr-dimitru commented Sep 15, 2018

Better and safer to use getCollection, as dot-notation doesn't work with collection names starting or ending with underscores:

db.getCollectionNames().forEach( function (d) {
  db.getCollection(d).dropIndexes();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment