2015-04-08 23 views
1

我需要遠程連接到我的MongoDB。所以我已經在mongod.conf中註明了bind_ip這一行,並在那裏設置了auth=true。現在我可以遠程連接了。如何在添加root用戶後在MongoDB中使用Auth

然後我鍵入以下的機器上運行的MongoDB:

  1. use admin
  2. db.addUser("myadmin", "mypw")

已成功創建,但現在當我嘗試在本地機器和我上遠程甚至連嘗試執行任何事情:not authorized on admin to execute command

即使我嘗試像這樣連接:mongo -u myadmin -p mypw(本地)

我獲得以下錯誤:

MongoDB shell version: 2.6.9 connecting to: test 2015-04-08T15:25:53.425+0200 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1260 exception: login failed

也許是因爲他試圖連接到test分貝?我怎樣才能指定哪個數據庫。遠程它不與mongo --host myurl -u myadmin-p mypw 與以下錯誤工作:

2015-04-08T14:31:00.373+0200 E QUERY Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at DB._authOrThrow (src/mongo/shell/db.js:1236:32) at (auth):6:8 at (auth):7:2 at src/mongo/shell/db.js:1236 exception: login failed

回答

7

請嘗試在連接到蒙戈外殼,如以下使用--authenticationDatabase

mongo -u myadmin -p mypw --authenticationDatabase admin 
+0

哇,固定它。非常感謝你! – Michael

+1

沒問題 - 幾周前得到同樣的問題,我花了一些時間弄清楚我做錯了什麼:) –

相關問題