Mongodb3安装授权

(1)

mongodb 官网下载解压包
mongodb-win32-x86_64-3.0.7.zip
解压释放在d盘,目录为mongodb,接下来手动创建data文件夹和log文件夹分别用于存放数据和日志。

(2)安装mongodb服务(不带auth参数安装)
cmd进入shell命令窗口

C:UsersAdministrator>d:

D:>cd D:mongodbin

mongod --logpath D:mongodblogmongodb.log --logappend --dbpath D:mongodbdata --serviceName MongoDB --install

紧接着执行服务启动命令:

net start MongoDB

(3)

cmd进入shell命令窗口

C:UsersAdministrator>d:

D:>cd D:mongodbin

D:mongodbin>mongo

MongoDB shell version: 3.0.7
connecting to: test

> use admin
switched to db admin
> db.createUser({user: "admin",pwd: "123456",roles: ["root"]})
Successfully added user: { "user" : "admin", "roles" : [ "root" ] }

> use admin
switched to db admin
> var schema = db.system.version.findOne({"_id" : "authSchema"})
> schema.currentVersion=3
> db.system.version.save(schema)

> use admin
switched to db admin
> db.createUser({user:"sa",pwd:"123456",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})

> use mtc
switched to db mtc
> db.createUser({user:"root",pwd:"123456",roles:[{role:"readWrite",db:"mtc"}]})

> db.auth("root","rtqw998358")

> exit

(4)执行服务停止命令
net stop MongoDB
紧接着执行服务安装命令(带auth参数):
mongod --logpath D:mongodblogmongodb.log --logappend --dbpath D:mongodbdata --serviceName MongoDB --auth --install
然后执行服务启动命令:
net start MongoDB

(5)然后就能通过的客户端工具mongodb vue进行远程授权连接啦!

原文地址:https://www.cnblogs.com/fx2008/p/5034902.html