MongoDB Shell:如何搜索与名称或正则表达式匹配的集合 [英] MongoDB shell: how to search for collections which match a name or regex

查看:70
本文介绍了MongoDB Shell:如何搜索与名称或正则表达式匹配的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用show collections时,它会返回所有集合的列表,这很长,我如何编写查询以返回与模式匹配的集合.我希望找到类似db.collections({name:/pattern/})的东西,但找不到

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

推荐答案

您可以使用 Array.filter() :

You can use db.getCollectionNames() with Array.filter():

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

这篇关于MongoDB Shell:如何搜索与名称或正则表达式匹配的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆