# network interfaces
net:
port: 27017
bindIp: 192.168.91.128 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
[root@xdhuxc ~]# mongo --host 192.168.91.128 -p 27017
MongoDB shell version v3.7.9-27-g793e59f
connecting to: mongodb://192.168.91.128:27017/
MongoDB server version: 3.7.9-27-g793e59f
Server has startup warnings:
2018-05-30T21:51:01.053+0800 I CONTROL [initandlisten]
2018-05-30T21:51:01.069+0800 I CONTROL [initandlisten] ** NOTE: This is a development version (3.7.9-27-g793e59f) of MongoDB.
2018-05-30T21:51:01.069+0800 I CONTROL [initandlisten] ** Not recommended for production.
2018-05-30T21:51:01.069+0800 I CONTROL [initandlisten]
2018-05-30T21:51:01.069+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-05-30T21:51:01.069+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-05-30T21:51:01.069+0800 I CONTROL [initandlisten]
2018-05-30T21:51:01.092+0800 I CONTROL [initandlisten]
2018-05-30T21:51:01.092+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-05-30T21:51:01.092+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-05-30T21:51:01.092+0800 I CONTROL [initandlisten]
2018-05-30T21:51:01.092+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-05-30T21:51:01.092+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-05-30T21:51:01.092+0800 I CONTROL [initandlisten]
>
> show dbs # 显示数据库列表。
admin 0.000GB
config 0.000GB
local 0.000GB
> use xdhuxc # 创建数据库并切换至该数据库。
switched to db xdhuxc
> show dbs # 再次显示数据库列表,却发现创建的数据库 xdhuxc 不在列表中。要显示新建的数据库,需要至少插入一个文档,空的数据库是不显示出来的。
admin 0.000GB
config 0.000GB
local 0.000GB
> db # 显示当前数据库。
xdhuxc
在 MongoDB 中,默认的数据库是 test,如果没有创建任何数据库,那么创建的集合和文档将存储在 test 数据库中。