2017-02-19 39 views
0

我已經通過Bitnami script在Google雲計算引擎上安裝了MongoDB。我可以在Google Cloud儀表板中看到虛擬機實例。我可以使用我部署的node.js應用程序連接到數據庫。我的應用程序工作得很好。Google Cloud上的Mongodb - 通過show dbs確認內容?

我弄不清楚的是如何獨立驗證Mongo數據庫中的內容。

在用於MongoDB虛擬機的Compute Cloud儀表板上,屏幕頂部有一個SSH下拉按鈕。點擊此按鈕打開瀏覽器框架。該框架通過https連接到VM實例,並確認登錄信息。我見過this related stackoverflow posting,我已經遇到了所有這些建議。在Google Cloud VM實例界面中確認的設置。當我輸入mongo時,我可以看到蒙戈殼。當我嘗試show dbs我回來意想不到的結果:

show dbs 
2017-02-19T05:51:45.161+0000 E QUERY [thread1] Error: listDatabases failed:{ 
     "ok" : 0, 
     "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }", 
     "code" : 13, 
     "codeName" : "Unauthorized" 
} : 

我怎樣才能做一個簡單的show dbs然後show collections最後db.foo.find()確認數據內容?

回答

0

Ouch。所以事實證明我錯過了一些東西。當我創建實例時,系統給我發送了一封確認郵件。在電子郵件中有幾個關鍵鏈接。

「連接」數據庫有兩種截然不同的方法。

首先是通過admin/login打開mongo shell界面。

$ mongo admin --username root -p 
MongoDB shell version v3.4.2 
Enter password: (password entered here) 
connecting to: mongodb:///opt/bitnami/mongodb/tmp/mongodb-27017.sock/admin 
MongoDB server version: 3.4.2 

這工作得很好,根本不需要傳輸SSH密鑰。 Reference link here。在這一點上,我可以

> show dbs 
admin 0.000GB 
local 0.000GB 
> use admin 
switched to db admin 
> show collections 
books 
system.users 
system.version 
> db.books.find() 
{ "_id" : ObjectId("58a900452c972b0010def8a7"), "title" : "Mr. Tickle", "author" : "Roger Hargreaves", "publishedDate" : "1971", "description" : "" } 
{ "_id" : ObjectId("58a900612c972b0010def8a8"), "title" : "Mr. Sneeze", "author" : "Roger Hargreaves", "publishedDate" : "1982", "description" : "" } 
{ "_id" : ObjectId("58a93a192c972b0010def8a9"), "title" : "Mr. Happy", "author" : "Roger Hargreaves", "publishedDate" : "1971", "description" : "" } 
> 

第二個方法是註冊SSH密鑰,通過these instructions over at Bitnami.com

在這種方法中,你必須首先通過谷歌雲接口的實例添加你的公共SSH密鑰。