在Ubuntu上配置MongoDB用户权限,需要按照以下步骤操作:
sudo apt-get update
sudo apt-get install -y mongodb
sudo systemctl start mongodb
userCredentials的数据库:mongo
use userCredentials
myUser的用户,密码为myPassword,并具有读取和写入数据的权限。请根据需要更改用户名、密码和权限:db.createUser({
user: "myUser",
pwd: "myPassword",
roles: [
{ role: "readWrite", db: "myDatabase" }
]
})
注意:将myDatabase替换为您要在其中设置用户权限的数据库名称。
exit
sudo systemctl restart mongodb
现在,您已经成功创建了一个具有读取和写入权限的用户。要使用此用户连接到MongoDB,请使用以下命令:
mongo -u myUser -p myPassword --authenticationDatabase userCredentials
这将允许您使用新创建的用户myUser连接到MongoDB,并具有指定的权限。