首页 > 数据库技术 > 详细

给你的mongodb设置密码吧!

时间:2020-09-03 16:22:21      阅读:54      评论:0      收藏:0      [点我收藏+]

D:\softinstall\MongoDB\Server\4.0\bin>mongo
MongoDB shell version v4.0.20
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("b9211a26-ffc7-44ec-af02-250393a60af0")
}
MongoDB server version: 4.0.20
Server has startup warnings:
2020-08-31T09:24:47.395+0800 I CONTROL [initandlisten]
2020-08-31T09:24:47.395+0800 I CONTROL [initandlisten] ** WARNING: Access contr
ol is not enabled for the database.
2020-08-31T09:24:47.395+0800 I CONTROL [initandlisten] ** Read and wri
te access to data and configuration is unrestricted.
2020-08-31T09:24:47.395+0800 I CONTROL [initandlisten]
---
Enable MongoDB‘s free cloud-based monitoring service, which will then receive an
d display
metrics about your deployment (disk utilization, CPU, operation statistics, etc)
.

The monitoring data will be available on a MongoDB website with a unique URL acc
essible to you
and anyone you share the URL with. MongoDB may use this information to make prod
uct
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeM
onitoring()
---

> use admin
switched to db admin
> db.createUser({user:‘root‘,pwd:‘123456‘,roles:[‘root‘]})
Successfully added user: { "user" : "root", "roles" : [ "root" ] }
> db.auth(‘root‘,‘123456‘)
1
> use mydb
switched to db mydb
> db.createUser({user:‘yx‘,pwd:‘123456‘,roles:[{role:‘readWrite,db:‘Article‘}]})

2020-09-03T15:36:00.248+0800 E QUERY [js] SyntaxError: missing } after proper
ty list @(shell):1:66
> db.createUser({user:‘yx‘,pwd:‘123456‘,roles:[{role:‘readWrite‘,db:‘Article‘}]
})
Successfully added user: {
"user" : "yx",
"roles" : [
{
"role" : "readWrite",
"db" : "Article"
}
]
}

 

给你的mongodb设置密码吧!

原文:https://www.cnblogs.com/Melissa888/p/13607970.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!