MongoDB remove mapreduce collection

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.


Temporary map-reduce table should be cleaned up when the connection which created them is closed:

map/reduce is invoked via a database command. The database creates a temporary collection to hold output of the operation. The collection is cleaned up when the client connection closes, or when explicitly dropped. Alternatively, one can specify a permanent output collection name. map and reduce functions are written in JavaScript and execute on the server.

-- MongoDB docs

If not, you could delete them using them same method you would delete any other collection. It might get a bit repetitive though.


Another way to achieve the same thing is this snippet:

db.system.namespaces.find({name: /tmp.mr/}).forEach(function(z) {
  try{
    db.getMongo().getCollection( z.name ).drop();
  } catch(err) {}
});

Pro: It won't try to collect all your namespaces into a JavaScript Array. MongoDB segfaults on too many namespaces.