给你的mongodb设置密码吧!
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"
}
]
}