MongoDB shell: how to search for collections which

2019-03-16 13:03发布

问题:

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) })