node.js - mongodb中的數據庫權限
問題描述
我在數據庫的admin中創建了一個管理員,角色是root,其他普通數據庫都沒創建,可用mongoose連接普通數據庫example怎么都連接不上,說not authorized on example to execute command ,加上admin的用戶名和密碼也無法登陸,報錯為Authentication failed。求大佬告知怎么改。
問題解答
回答1:1、admin的用戶名和密碼也無法登陸,報錯為Authentication failed。
使用管理員(你配置的角色為root)登錄時候,請配置 authenticationDatabase 'admin';例如在mongo命令行下:
mongo -u 'root' -p 'root' --authenticationDatabase 'admin'
2、可用mongoose連接普通數據庫example怎么都連接不上,說not authorized on example to execute command
正確的步驟是,應該用管理員創建應用紅所需的數據庫用戶,分配權限,然后再登錄。例如:
創建用戶/分配權限,指定用戶名、權限、對應的數據庫,例如命令行下:db.createUser( {
user: 'app',pwd: 'app',roles: [ { role: 'readWrite', db: 'example' } ]
} )
登錄時,連接example數據庫,例如命令行下:
mongo -u 'app' -p 'app' --authenticationDatabase 'example'
供參考。
Love MongoDB ! Have Fun!
我最近剛好遇到這個問題了,你可以看看這個 http://kdylan.me/2016/12/11/m...
相關文章:
1. dockerfile - [docker build image失敗- npm install]2. docker安裝后出現Cannot connect to the Docker daemon.3. docker gitlab 如何git clone?4. python - pandas按照列A和列B分組,將列C求平均數,怎樣才能生成一個列A,B,C的dataframe5. 求一個mySQL安裝包6. docker-machine添加一個已有的docker主機問題7. 使用mysql自增主鍵遇到的問題8. css3 - [CSS] 動畫效果 3D翻轉bug9. java - Tomcat 不同的域名訪問同一個項目的不同網頁10. javascript - 文件改后綴后怎么獲得原來是什么類型的
