安装
更新brew并安装
sudo brew install mongodb
或者下载中心下载安装,下载后解压重命名等
https://www.mongodb.com/download-center#atlas
设置环境变量"open -e ./bash_profile"
export PATH=/usr/local/mongodb/bin:$PATH
创建一个数据库存储目录 :
sudo mkdir /usr/local/mongodb/data
创建一个日志目录 :
sudo mkdir /usr/local/mongodb/logs
创建配置文件
vi /usr/local/mongodb/bin/mongodb.conf
port=27017
dbpath=/usr/local/mongodb/data/
logpath=/usr/local/mongodb/log/mongodb.log
fork = true
启动服务
sudo mongod -config mongodb.conf
更换启动数据库路径
sudo mongod --dbpath /data/db
启动客户端
mongo
测试
>db
test
切换或者创建数据库
>use exam
switched to db exam
文档记录查询
>db.question.find()
{ "_id" : ObjectId("5b056cce2f6df08d6a6a1a6c"), "_class" : "com.qz.zeroexam.question.QuestionBean", "title" : "1122112", "type" : "选择题", "createTime" : ISODate("2018-05-23T13:29:50.440Z") }
{ "_id" : ObjectId("5b0589972f6df0934de22519"), "_class" : "com.qz.zeroexam.question.bean.Question", "title" : "1+1=?", "type" : "选择题", "createTime" : ISODate("2018-05-23T15:32:39.310Z"), "options" : [ { "_id" : null, "name" : "1", "isCorrect" : 0 }, { "_id" : null, "name" : "2", "isCorrect" : 1 }, { "_id" : null, "name" : "3", "isCorrect" : 0 }, { "_id" : null, "name" : "4", "isCorrect" : 0 } ] }
{ "_id" : ObjectId("5b0590662f6df0934de2251a"), "_class" : "com.qz.zeroexam.question.bean.Question", "title" : "计算一下:1+1=??", "type" : "选择题", "createTime" : ISODate("2018-05-23T16:01:42.647Z"), "options" : [ { "_id" : null, "name" : "1", "isCorrect" : 0 }, { "_id" : null, "name" : "2", "isCorrect" : 1 }, { "_id" : null, "name" : "3", "isCorrect" : 0 }, { "_id" : null, "name" : "4", "isCorrect" : 0 } ] }
网友评论