如何通过shell脚本操作MongoDB

来源:互联网 发布:ct原理与图像重建算法 编辑:程序博客网 时间:2024/06/05 04:01

例如:我想查询下有哪些数据库

[root@ser6-51 dandan]# vi g.sh

添加:

sql="show dbs"

echo $sql | mongo -u superuser -p 123456 admin--shell


[root@ser6-51 dandan]# sh g.sh
MongoDB shell version: 3.0.4
connecting to: admin
type "help" for help
admin     0.078GB
local     0.453GB
myTest    0.078GB
myTest()  0.078GB
bye


0 0