我创建了一个用户,"test_user"
有关MongoDB的分贝"test_db"
并授予readWrite
作用如下“未授权”错误而从蒙戈外壳查询,从RoboMongo
db.createUser(
{
user : "test_user",
pwd : "password",
roles : [
{
role : "readWrite",
db : "test_db"
}
]
}
)
蒙戈说:Successfully added user
一切都很好,我用RoboMongo连接到我的数据库,并能够创建和列出集合。
但是,当我连接使用shell从我的机器蒙戈如下
mongo -u 'test_user' --authenticationDatabase 'test_db' -p 'password'
我无法列出或创建集合。 Mongo说
E QUERY [thread1] Error: listCollections failed: {
"ok" : 0,
"errmsg" : "not authorized on test to execute command { listCollections: 1.0, filter: {} }",
"code" : 13,
"codeName" : "Unauthorized"
}
当我在shell中输入show collections
。
我缺少什么?
奇怪的是,在尝试列出集合或查询之前,我必须在mongo shell中使用'test_db'。尽管我在登录脚本中使用了'--authenticationDatabase'参数,mongo并不会自动为您选择所提到的db。你必须自己做。 –