首页 文章

Google Cloud上的Mongodb - 通过show dbs确认内容?

提问于
浏览
0

我通过Bitnami script在Google Cloud Compute Engine上安装了MongoDB . 我可以在Google Cloud信息中心中看到vm实例 . 我可以使用我部署的node.js应用程序连接到数据库 . 我的应用程序工作正常 .

我无法弄清楚的是如何独立验证Mongo数据库中的内容 .

在Mongo DB VM的Compute Cloud仪表板上,屏幕顶部有一个SSH下拉按钮 . 单击此按钮可打开浏览器框架 . 框架通过https连接到VM实例,并确认登录信息 . 我见过this related stackoverflow posting,我已经满足了所有这些建议 . 在Google Cloud VM实例界面中确认的设置 . 当我输入 mongo 时,我可以看到mongo shell . 当我尝试 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() 来确认数据内容?

1 回答

  • 0

    哎哟 . 所以事实证明我错过了一些东西 . 当我创建实例时,系统向我发送了一封确认电子邮件 . 在电子邮件中有几个关键链接 .

    有两种截然不同的方法可以“连接”到数据库 .

    第一种是通过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" : "" }
    >
    

    第二种方法是通过these instructions over at Bitnami.com注册SSH密钥

    在此方法中,您必须首先通过Google Cloud界面将公共SSH密钥添加到实例 .

相关问题