javascript - 如何一次删除大量的mongodb集合?

标签 javascript mongodb database

我的数据库中有很多 mongodb 集合需要删除。它们都有相似的名称,如果只使用通配符,则很容易删除它们。但看起来他们做不到。

有没有办法一次选择一堆集合来删除它们?

最佳答案

对于正则表达式,您可以使用 string.match

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

关于javascript - 如何一次删除大量的mongodb集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11206890/

相关文章:

javascript - 无法在 html 中创建选项卡式面板

javascript - 无法获取选择元素中的选定元素

database - Mongoose 错误: The MongoDB server disallows overwriting documents using `updateOne`

database - 使用继承在 Postgres 中反反模式 (OTLT)

jquery - 将 jquery post 数据保存在变量中

javascript - 整个滚动后的 jQuery 回调函数

javascript - React.js 状态问题

c# - 在 C# dockerfile 中运行可执行文件

java - 为什么我的 Mongo 聚合不能在嵌套文档上正常工作?

database - CakePHP:使用 save() 添加/减去?