• 下表列出了 RDBMS 与 MongoDB 对应的术语


    MongoDB内容学习
    参照对比.png
  • 通过mongo shell 建立连接或者通过代码服务器 启动 密码 asd123

    MongoDB内容学习
    image.png

mongo ds145043.mlab.com:45043/restful-api-production -u root -p asd123 cmd连接
mongodb://root:[email protected]:45043/restful-api-production 代码服务连接

  • MongoDB 连接命令格式
    使用用户名和密码连接到 MongoDB 服务器,你必须使用 'username:[email protected]/dbname' 格式,'username'为用户名,'password' 为密码。
    使用用户名和密码连接登陆到默认数据库:
module.exports = {
    // mongoURI: "mongodb://root:[email protected]:45043/restful-api-production" // 远程数据库 mlab
    mongoURI: "mongodb://root:[email protected]:27017/restful-api-pro" // 本地数据库
}
db.users.drop
MongoDB内容学习
image.png

db.createCollection(name, options)创建集合
name: 要创建的集合名称
options: 可选参数, 指定有关内存大小及索引的选项
如果要查看已有集合,可以使用show collections 命令
db.mycol2.insert({"name" : "菜鸟教程"}) ,直接插入也会自动创建集合(表格)
db.collection.drop() 删除集合

  • MongoDB 使用 insert() 或 save() 方法向集合中插入文档,语法如下:
    db.COLLECTION_NAME.insert(document)
    db.col.find()来查看数据的数据
    MongoDB内容学习
    image.png

    MongoDB内容学习
    image.png

    [图片上传中...(image.png-4983ed-1541409937316-0)]
MongoDB内容学习
删除行

相关文章: