Search code examples
mongodbmongodb-.net-driver

MongoDB remove mapreduce collection


Due to error in client code, mongodb have created many "mr.mapreduce...." collections, how to remove them all (by mask maybe).


Solution

  • I run script in interactive shell:

    function f() {
        var names = db.getCollectionNames();
        for(var i = 0; i < names.length; i++){
        if(names[i].indexOf("mr.") == 0){
        db[names[i]].drop();}}};
    f();
    

    It resolved my problem.