如何在Shell脚本中获取Mongo数据库集合的确切列表 [英] How to get exact list of collections form mongo database in shell script

查看:436
本文介绍了如何在Shell脚本中获取Mongo数据库集合的确切列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从mongo数据库获取集合名称列表. 因此,我在shell脚本中使用以下命令:

I would like to get the collection names list from mongo database. So, I use the following command in shell script :

collections = mongo $dbName --eval "db.getCollectionNames()"

collections=mongo $dbName --eval "db.getCollectionNames()"

此命令的输出结果为

"MongoDB shell版本:2.2.0连接到:cm_v2 col1,col2,col3,col4"

"MongoDB shell version: 2.2.0 connecting to: cm_v2 col1,col2,col3,col4"

我只想获取集合名称,例如:col,col2,col3,col4. 因此,我应该如何从结果中删除类似版本的输出.

I would like to get only the collections name such as : col,col2,col3,col4. So, how should I delete the output like version from result.

推荐答案

使用 --quiet 标志

collections=mongo $dbName --quiet --eval "db.getCollectionNames()"

这篇关于如何在Shell脚本中获取Mongo数据库集合的确切列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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