0

I registered for a free sandbox database on MongoHQ.

As I am starting to use mongoDB I thought it would be a good idea to connect to MongoHQ database from the mongo console and run some commands before using it in any program.

I tried connecting to my database using:

Here testuser is my username and 123456 is my password (I know posting user id and passowrd on forums is bad, this user is temporary and will be deleted by me later).

mongo oceanic.mongohq.com:10076/tnh_data -u testUser -p 123456

and I got this:

MongoDB shell version: 2.4.9 connecting to: oceanic.mongohq.com:10076/tnh_data

Hoping that everything is running fine I tried running a few commands, but I am getting a not authorized error.

> show dbs
Sat Apr 19 22:00:18.090 listDatabases failed:{ "ok" : 0, "errmsg" : "unauthorized" } at src/mongo/shell/mongo.js:46
> use learn
switched to db learn
> db.collection0.insert({name: 'Harry', gender: 'Male'})
not authorized for insert on learn.collection0

Please help me what am I doing wrong ?

Just for the information. I created the users using the web interface on mongoHQ.

Ishan
  • 3,303
  • 5
  • 29
  • 47

1 Answers1

0

When using MongoHQ sandbox plans and logging in from the console, there are a couple of things that are at play:

  1. When you connected, using the string above, you are already in your database (tnh_data)
  2. You do not have admin-level access, so "show dbs" will not work in MongoDB console.

So, in MongoDB console, connect again using the same string you started with and, once connected, run this command: "show collections".

Also, without trying to switch to another database, run your insert again. It should work normally this time.

Hope this information is helpful!

Jason McCay
  • 3,295
  • 1
  • 13
  • 8
  • Thanks for clarifying things for me. Can you please tell me how to get admin-level access. And thus how to add and remove databases. Sorry for these newbie questions. I am pretty new to MongoDB. – Ishan Apr 19 '14 at 19:14
  • You can add additional databases through the MongoHQ web interface. If you want the ability to add multiple databases to a single MongoDB deployment, MongoHQ has Elastic Deployments. These allow you to create multiple databases and have increasing levels of access. Is there something specific that you need admin-access for? It does not come standard with the free/sandbox plans. – Jason McCay Apr 20 '14 at 04:15
  • Thanks Jason . I just wanted to know how to get admin access. I don't have got to do anything with it now. I thought that this information will be handy in future. – Ishan Apr 20 '14 at 14:41