mongodb的简单使用

学习目标
  1. 掌握 服务端的启动
  2. 掌握 客户端的使用
  3. 掌握 mongodb的数据库和集合命令
  4. 了解 文档中的_id字段

1. mongodb服务端的启动

mongodb服务端启动分别两种方式:

1.1 测试方式启动

1.2 生产环境正式的启动方式

启动: sudo mongod [--auth --dbpath=dbpath --logpath=logpath --append --fork][-–f logfile ]

1.3 查看是否启动成功

ps aux | grep mongod

2. 启动mongodb的客户端:进入mongo shell

3. mongodb的简单使用

开启mongodb server的情况下,在进入mongo shell后,就可以做简单的使用了

3.1 mongodb数据库的命令

3.2 mongodb集合的命令

3.3 简单练习

在mongo shell中输入下列命令,查看结果

 

3.3 mongodb中常见的数据类型(了解)

3.3.1 常见类型
3.3.2 注意点

小结

  1. 服务端的启动

    • sudo mongod --dbpath=数据库路径
  2. 进入mongo shell客户端

    • mongo
  3. mongodb的数据库和集合命令

    • show dbs
    • use db_name
    • show collections
    • db
    • db.集合名.drop()
    • db.dropDatabase()
    • exit
  4. 了解文档中的_id字段