MongoDB shell: how to search for collections which match a name or regex

旧时模样 提交于 2019-12-04 08:57:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!