Question

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.

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top