MongoDB的安裝
Step1. 打開MongoDB產品下載頁面https://www.mongodb.com/download-center?jmp=nav#community,選擇Windows Server 2008 R2 64-bit and later, with SSL support x64,點擊下載。
Step2. 雙擊上一步下載的安裝包,根據安裝嚮導的提示,一直next,選擇complete,最後finish,即安裝成功。注意mongodb的安裝目錄。
MongoDB的配置
Step1. 打開mongoDB的bin,記住它的路徑,我的是在C:\Program Files\MongoDB\Server\3.4\bin。接下來,win+R—cmd,打開了命令行,再 cd C:\Program Files\MongoDB\Server\3.4\bin,接下來對mongoDB的配置將在此路徑中進行。
Step2. 創建數據庫文件的存放位置
…\bin>mongod,這裏默認指定了dbpath=C:\data\db,但需要我們提前在C盤根目錄下創建data\db,否則這一步會出現"dbpath=C:\data\db not found"的錯誤提示。不用管這裏的Warning: access is not enabled for the database。
另外,我們可以自行指定dbpath=D:\my test\data\db,前提是它已經創建好,否則還是出現not found的錯誤提示。命令行中可以這樣敲…bin>mongod --dbpath “D:\my test\data\db”。不用管這裏的Warning: access is not enabled for the database,也可以指定logpath,如mongod --dbpath “D:\my test\data\db” --logpath “D:\my test\data\log\mongodb.log”,那麼控制檯顯示的內容將保存到日誌中。
Step3. 在瀏覽器中輸入網址:http://localhost:27017/ 。如果服務啓動成功會看到以下一段話:
It looks like you are trying to access MongoDB over HTTP on the native driver port.
Step4. Step2.的cmd窗口不要關,回到bin文件夾下,管理員身份運行mongo.exe。
嘗試敲入以下命令:db; use admin; db.auth(“admin”, “admin”)
>db
test
>use admin
switched to db admin
當我們敲入db.auth(“admin”, “admin”)時,返回爲0,出現Error: Authentication failed。也正是這個原因導致robomongo無法連接
>db.auth("admin","admin")
Error: Authentication failed.
0
解決方法是手動添加admin賬戶,創建成功後,再次db.auth(“admin”, “admin”),返回1
db.createUser(
{
user: "admin",
pwd: "admin",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
>db.auth("admin","admin")
1
以上之後,便可成功授權successfully authenticated。
轉載地址:https://www.cnblogs.com/shuibingyue/p/7101361.html