node.js - mongodb中的數(shù)據(jù)庫權(quán)限
問題描述
我在數(shù)據(jù)庫的admin中創(chuàng)建了一個管理員,角色是root,其他普通數(shù)據(jù)庫都沒創(chuàng)建,可用mongoose連接普通數(shù)據(jù)庫example怎么都連接不上,說not authorized on example to execute command ,加上admin的用戶名和密碼也無法登陸,報(bào)錯為Authentication failed。求大佬告知怎么改。
問題解答
回答1:1、admin的用戶名和密碼也無法登陸,報(bào)錯為Authentication failed。
使用管理員(你配置的角色為root)登錄時(shí)候,請配置 authenticationDatabase 'admin';例如在mongo命令行下:
mongo -u 'root' -p 'root' --authenticationDatabase 'admin'
2、可用mongoose連接普通數(shù)據(jù)庫example怎么都連接不上,說not authorized on example to execute command
正確的步驟是,應(yīng)該用管理員創(chuàng)建應(yīng)用紅所需的數(shù)據(jù)庫用戶,分配權(quán)限,然后再登錄。例如:
創(chuàng)建用戶/分配權(quán)限,指定用戶名、權(quán)限、對應(yīng)的數(shù)據(jù)庫,例如命令行下:db.createUser( {
user: 'app',pwd: 'app',roles: [ { role: 'readWrite', db: 'example' } ]
} )
登錄時(shí),連接example數(shù)據(jù)庫,例如命令行下:
mongo -u 'app' -p 'app' --authenticationDatabase 'example'
供參考。
Love MongoDB ! Have Fun!
我最近剛好遇到這個問題了,你可以看看這個 http://kdylan.me/2016/12/11/m...
相關(guān)文章:
1. objective-c - iOS怎么實(shí)現(xiàn)像QQ或者微信的實(shí)時(shí)推送2. 網(wǎng)頁爬蟲 - python爬蟲翻頁問題,請問各位大神我這段代碼怎樣翻頁,還有價(jià)格要登陸后才能看到,應(yīng)該怎么解決3. 求大神幫我看看是哪里寫錯了 感謝細(xì)心解答4. MySQL客戶端吃掉了SQL注解?5. 數(shù)據(jù)庫 - MySQL 單表500W+數(shù)據(jù),查詢超時(shí),如何優(yōu)化呢?6. php自學(xué)從哪里開始?7. mysql - AttributeError: ’module’ object has no attribute ’MatchType’8. android - Windows系統(tǒng)下運(yùn)行react-native App時(shí),報(bào)下面的錯誤?9. phpstady在win10上運(yùn)行10. javascript - 圖片能在網(wǎng)站顯示,但控制臺仍舊報(bào)錯403 (Forbidden)
