Kyaw Min Thu L Kyaw Min Thu L - 1 year ago 111
Bash Question

How to get exact list of collections form mongo database in shell script

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


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

The output result of this command is

"MongoDB shell version: 2.2.0 connecting to: cm_v2 col1,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.

Answer Source

use --quiet flag

collections=mongo $dbName --quiet --eval "db.getCollectionNames()"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download