MongoDB Shell是MongoDB自带的交互式Javascript shell,用来对MongoDB进行操作和管理的交互式环境。 当你进入mongoDB后台后,它默认会链接到 test 文档(数据库):
1 2 3 4 5 6 7 8 9 10
$ mongo MongoDB shell version v3.4.1 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.1 Server has startup warnings: 2017-02-16T10:04:47.321+0800 I CONTROL [initandlisten] 2017-02-16T10:04:47.321+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-02-16T10:04:47.321+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-02-16T10:04:47.321+0800 I CONTROL [initandlisten] >
数据库基本操作
1 2 3 4 5 6 7 8 9 10 11 12
> db //查看当前数据库 test > show dbs //查看所有数据库 admin 0.000GB local 0.000GB test 0.000GB > use local //切换数据库 switched to db local > show collections //查询当前数据库所有表(集合).show tables也可以 col message post_total