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

MongoDB,V3.2版本,官網說的很詳細,見連接:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/mongodb

 

一、建立配置文件,shell

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

 

二、安裝mongodbnpm

yum install -y mongodb-org服務器

 

三、啓動mongodbmongoose

service mongod start測試

 

四、暫停服務url

service mongod stopspa

 

五、重啓服務rest

service mongod restart

 

六、開機啓動

chkconfig mongod on

 

另:能夠重啓一下服務器進行測試,shutdown -r now

 

七、安裝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()
相關文章
相關標籤/搜索