问题
when I use show collections it returns a list of all collections which is pretty long, how can I write a query to return collections matching a pattern. I was hoping for something like db.collections({name:/pattern/}) but couldn't find
回答1:
You can use db.getCollectionNames() with Array.filter():
db.getCollectionNames().filter(function (collection) { return /pattern/.test(collection) })
来源:https://stackoverflow.com/questions/26684307/mongodb-shell-how-to-search-for-collections-which-match-a-name-or-regex