MongoDB wrapper: how to search for collections that match name or regex

when i use the show collections it returns a list of all collections which is quite long, how can i write a query to return collections that match the pattern. I was hoping for something like db.collections ({name: / pattern /}) but couldn't find

+3


source to share


1 answer


You can use db.getCollectionNames()

with Array.filter()

:



db.getCollectionNames().filter(function (collection) { return /pattern/.test(collection) })

      

+12


source







All Articles