如何在mongo中显示集合列表时过滤结果?

时间:2013-09-18 16:47:25

标签: mongodb

“show collections”命令显示整个集合的列表。我想知道是否有办法使用过滤器列出或搜索特定的集合?

E.g:

show collections

allocation
axis_selection
dummy
results
param_test

但我只想要以'a'(我的过滤器)

开头的集合
show collections

allocation
axis_selection

1 个答案:

答案 0 :(得分:11)

您无法修改show collections命令的打印内容。但您可以使用db.getCollectionNames()方法获取集合名称并手动过滤名称数组:

db.getCollectionNames().filter(function (c) { return c.indexOf('a') == 0; })