0

I've installed a MongoDB on Google Cloud Compute Engine via a Bitnami script. I can see the vm instance in the Google Cloud dashboard. I can connect to the database using my deployed node.js app. My app works just fine.

What I can't figure out is how to independently verify the content in the Mongo database.

On the Compute Cloud dashboard for the Mongo DB VM, there is a SSH pulldown button at the top of the screen. Clicking this button opens up a browser frame. The frame connects to the VM instance via https, and confirms login info. I've seen this related stackoverflow posting, and I've met all of these suggestions. Settings confirmed at the Google Cloud VM instance interface. When I type mongo I can see the mongo shell. When I try show dbs I get back unexpected results:

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"
} :

How can I do a simple show dbs and then show collections and finally db.foo.find() to confirm data content?

Community
  • 1
  • 1
zipzit
  • 3,778
  • 4
  • 35
  • 63

1 Answers1

0

Ouch. So it turns out I missed something. When I created the instance the system sent me an confirmation email. In the email were a couple of key links.

There are two very different methods to "connect" to the database.

The first is to open the mongo shell interface via an admin / login.

$ 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

This worked quite well, without having to transfer SSH keys at all. Reference link here. At this point I could

> 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" : "" }
> 

The second method is to register SSH keys, via these instructions over at Bitnami.com

In this method, you have to first add your public SSH key via the Google Cloud interface to the instance.

zipzit
  • 3,778
  • 4
  • 35
  • 63