如何一次删除大量的mongodb集合? [英] How to delete lots of mongodb collections at once?

查看:1016
本文介绍了如何一次删除大量的mongodb集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中有很多mongodb集合,我需要删除。它们都有类似的名称,如果只能使用通配符,那么很容易删除它们。但它看起来不像他们可以。

There are a lot of mongodb collections in my database that I need to delete. They all have similar names, and it would be easy to delete them if only wildcard characters could be used. But it doesn't look like they can.

有一种方法来一次选择一组集合来删除它们?

Is there a way to select a bunch of collections at once to delete them?

推荐答案

对于regex,你可以使用string.match

For regex you can use string.match

db.getCollectionNames().forEach(function(c) {
    if(!c.match("^system.indexes")) { 
        db.getCollection(c).drop();
    }
  });

这篇关于如何一次删除大量的mongodb集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆