mongodb4.x 配置用户认证登录
在mongodb安装目录下的 mongod.cfg 修改
security: authorization: enabled
改好后重启mongodb服务
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: D:\MongoDB\data\db journal: enabled: true # engine: # mmapv1: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: true path: D:\MongoDB\data\log\mongod.log # network interfaces net: port: 27017 bindIp: 127.0.0.1 #processManagement: security: authorization: enabled #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp:
进入cmd,输入mongo,进入mongodb的命令页面
>mongo
> use admin #进入admin数据库
switched to db admin
>db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin"}]})
查看数据库
show databases;
创建test库,并在test库创建用户
db.createUser({user:'test',pwd:'123456',roles:[{role:'readWrite',db:'test'},{role:'dbAdmin',db:'test'}]})
向test库中插入一条新纪录
db.global_var.insert({name:"xxx",values:[123,3333],description:"xxxxxx"})
本文来自博客园,作者:margo,转载请注明原文链接:https://www.cnblogs.com/ZMargo/articles/11927731.html