Skip to content

Instantly share code, notes, and snippets.

@Climax777
Climax777 / collectionsafedropper.js
Created May 26, 2014 12:28
MongoDB shell helper for dropping a collection while keeping the indexes
collectionsafedropper = function(database,col) {
var thedb = db.getSiblingDB(database);
var thecoll = thedb[col];
var indexes = thecoll.getIndexes();
print("Dropping: ", database.toString() + "." + col.toString());
thecoll.drop();
indexes.forEach(function(index) {
var key = index.key;
var options = {};