Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
127 views
Welcome To Ask or Share your Answers For Others

1 Answer

For regex you can use string.match

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...