在Windows上安装社区版MongoDB
2019-12-27 本文已影响0人
爱的旋转体
1.官网下载社区版mongo:

2.安装:








3.将mongo添加到环境变量:


4.授权用户访问权限:
安装完成后MongoDB默认只能本机访问,并且不需要密码;
1)命令行创建数据库
mongo
use test

2)在test数据库中创建test用户:
db.createUser({ user: "test", pwd: "test", roles: [{ role: "readWrite", db: "test" }] })
3)修改MongoDB安装目录中的配置文件 bin/mongod.cfg:
如果需要远程连接,将bindIp中的127.0.0.1改为0.0.0.0;
将#security:的注释去掉,然后添加authorization: enabled #注意authorization前面要有两个空格。
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: C:\tools\MongoDB\data\db
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: C:\tools\MongoDB\data\log\mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
#processManagement:
#security:
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
4)重启MongoDB服务:
以管理员身份运行,在新的控制台输入以下命令:
net stop MongoDB
net start MongoDB
如果启动失败,检查配置文件是否书写正确,authorization前面有两个空格。