2017-02-19 28 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密钥。

相关问题