使用鉴权方式打开交互界面:注意这里的admin user alice是数据库的admin的账号,而不是集群的账号。
/usr/local/mongodb-4.2.8/bin/mongo -host 10.109.3.72 -port 27017 -u "alice" -p "123456" --authenticationDatabase admin
# add read&write user
rs0:PRIMARY> use test
switched to db test
rs0:PRIMARY> db.createUser({
... ... ... ... user:"abc",
... ... ... ... pwd: passwordPrompt(),
... ... ... ... roles: [{ role: "readWrite", db: "test"}]
... ... ... ... }
... ... ... ... )
# add read user
rs0:PRIMARY> db.createUser({
... ... ... ... ... user:"c_read",
... ... ... ... ... pwd: passwordPrompt(),
... ... ... ... ... roles: [{ role: "read", db: "test"}]
... ... ... ... ... }
... ... ... ... ... )