MongoDB基础知识

时间:2020-09-04 17:36:28   收藏:0   阅读:68

MongoDB -非关系型数据库

MongoDB数据库介绍

------------面向文档的数据库 {"foo":3,"greeting":"Hello World!"}

特点:

理解:

命名规则:

 知识点:

安装配置MongoDB 

启动

windows:  mongod.exe --dbpath  D:\\MongoDB\\data         路径 数据存储地址

Linux:sudo service mongod start

windows下启动链接Mongo:

1.找到安装目录下bin文件夹,按住shift+鼠标右键,选择打开cmd(win10打开Windows Powershell),输入:mongod --dbpath  D:\\MongoDB\\data ,或者mongod.exe --dbpath  D:\\MongoDB\\data 

2.链接mongodb:    找到安装目录下bin文件夹,按住shift+鼠标右键,选择打开cmd(win10打开Windows Powershell),输入:mongo ,或者mongo.exe

注意:

  输入命令行后出现:Suggestion [3,General]: 找不到命令 mongo,但它确实存在于当前位置。默认情况下,Windows PowerShell 不会从当前位置加载命令 。如果信任此命令,请改为键入“.\mongo”。有关详细信息,请参阅 "get-help about_Command_Precedence"。

  则按要求在前面加上“.\”即可正常运行

 

 

使用命令行操作数据库(CRUD  ——create read update delete) 

查看数据库

show dbs;

创建数据库

use students

添加数据

stu = {name:"Jhon",age:12}

插入一条数据

db.students.insert(stu)       

db.students.insertOne(stu)

插入多条数据

db.students.insertMany(stu)                   

查询数据

db.students.find()

查询一条数据

db.students.findOne()

查询多条数据

db.students.findMany()

修改数据

1.修改的数据查询出来,得到一个对像:stu_obj = db.students.findOne()         

2.将对象进行变更:stu_obj.name = "amy"

3.变更对象:db.students.update({name:"Jhon"},stu_obj)

注意,如果直接更改,会导致同条数据其他数据丢失

db.students.update(1,2)   1---条件,2---更改内容

删除数据

db.students.remove({name:‘Jhon‘})

也可以直接传入一个空字符----清空数据库:db.students.remove({})         

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!