- 启动Mongodb服务
- 随便进入一个目录
- 连接到Mongodb服务:执行
mongo - 显示有哪些数据库:执行
show dbs

- 进入某个数据库:执行
use comment1(如果进入的数据库不存在则会先创建)

- 查表(集合):执行
show collections

- 在数据库中插入的数据:在要操作的数据库下,执行:
db.users.insert({username: 'wangwu', password:'abc'})

- 查询数据库中的数据:在要操作的数据库下,执行:
db.users.find()

9. 按条件查询数据:db.users.find({city: 'shanghai'})

10. 排序:db.users.find().sort({age: 1}) (正序)











