【安装MongoDB】CentOS7 下安装NodeJs+Express+MongoDB+Redis

MongoDB,V3.2版本,官网说的很详细,见链接:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

 

1、创建配置文件,

vi /etc/yum.repos.d/mongodb-org-2.6.repo

[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

 

2、安装mongodb

yum install -y mongodb-org

 

3、启动mongodb

service mongod start

 

4、暂停服务

service mongod stop

 

5、重启服务

service mongod restart

 

6、开机启动

chkconfig mongod on

 

另:可以重启一下服务器进行测试,shutdown -r now

 

7、安装mongoose

npm install mongoose --save

 

mongodb的CURD如下:

————进入mongo shell页面————
mongo


————创建数据库/创建表———— use testdatabase db.createCollection('testtable') ————显示所有表———— use testdatabase show collections ————插入数据———— use testdatabase coll = db.getCollection('testtable') coll.insert({name:"ZhangSan",password:"123456"}) coll.insert({name:"WangEr",password:"nicai"}) ————查询数据———— use testdatabase coll = db.getCollection('testtable') coll.find()

 

posted @ 2016-06-17 23:29  Fico  阅读(947)  评论(0编辑  收藏  举报