一、MongoDB简介
基于分布式文件存储的数据库。介于关系数据库和非关系数据库之间的产品,是非关系数据库
二、MongoDB安装命令
1、直接输入命令
brew install mongodb :安装
brew uninstall mongodb:卸载
2、启动mongodb
mongodb --config /usr/local/ect/mongodb.conf
注:brew services start mongodb(mongodb链接失败的解决方法)
3、使用
mongo
Last login: Fri Jul 6 10:40:00 on ttys000
XXXXXX$ mongo
MongoDB shell version: 3.2.8
connecting to: test
>
三、MongoDB的基本操作
1、show dbs :查看多少数据库
2、use imooc:切换数据库
3、db.dropDatabase():将数据库进行删除
4、db.imooc_collection.insert({x:1}):插入数据
5、show collections
6、db.imooc_collection.find():查询表中的数据
7、for(i=3;i<100;i++)db.imooc_collection.insert({x:i}):用循环插入多条数据
8、db.imooc_collection.find().count():表中的数据多少条
9、db.imooc_collection.find.skip(3).limit(2).sort({x:1})
10、db.imooc_collection.find({x:1}):条件查询表中数据
11、db.imooc_collection.update({x:1},{x:999}):修改表中数据
12、db.imooc_collection.updata({c:1},{$set:{c:2}},,false,true)
13、 db.imooc_collection.remove({c:2}):表内数据删除
14、db.imooc_collection.drop()
15、show tables:查看有多少表