【问题标题】:Mongodb on Google Cloud -- Confirm content via show dbs?Google Cloud 上的 Mongodb -- 通过 show dbs 确认内容?
【发布时间】:2017-02-19 06:10:35
【问题描述】:

我通过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()来确认数据内容?

【问题讨论】:

    标签: mongodb google-cloud-platform google-compute-engine


    【解决方案1】:

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

    有两种非常不同的方法可以“连接”到数据库。

    首先是通过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 密钥添加到实例中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 2021-12-12
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 2019-07-02
      • 2018-01-15
      相关资源
      最近更新 更多