我創建了一個用戶,"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。你必須自己做。 –