即mongo命令的参数
mongo test #连接到test库
mongo 192.168.7.221/test<span style="white-space:pre"> </span>#连接到指定IP的test库
mongo 192.168.7.221:27018/test #连接到指定IP,指定端口的test库
--eval
同mysql -e,不进入到mongo命令行执行--eval后面的语句
<pre name="code" class="sql"><pre name="code" class="sql">#mongo cric
MongoDB shell version: 3.0.5
connecting to: cric
Server has startup warnings:
2015-08-24T11:17:53.412+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-08-24T11:17:53.421+0800 I CONTROL [initandlisten]
> db.()
3
#mongo cric --eval "printjson(db.())"
MongoDB shell version: 3.0.5
connecting to: cric
3
-u(--username)
指定用户
-p(--password)
指定密码
--quiet
屏蔽版本等信息
<pre name="code" class="sql"># mongo
MongoDB shell version: 3.0.5
connecting to: test
Server has startup warnings:
2015-08-24T11:17:53.412+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-08-24T11:17:53.421+0800 I CONTROL [initandlisten]
>
#mongo --quiet
>