1

I'm using the Nodejitsu and their packaged Mongolab MongoDB database. I ran the command jitsu databases get myDB and I got instructions on how to connect via mongo CLI. The out put of that command has a line that says the following:

help:    Connect with the `mongo` cli client:
help:    
             $ mongo ds039267.mongolab.com:39267/nodejitsu_xxxxxx_nodejitsudb8577296358 -u nodejitsu_xxxxxx -p mypassword

NOTE: This is the first time I am connecting to this instance via the CLI. I only created the database name through jitsu databases create…

I am using Mongo Shell version 1.8.3. I connected to my instance of MongoDB. I tried running the command: show dbs and I got:

uncaught exception: listDatabases failed:{ "ok" : 0, "errmsg" : "unauthorized" }

I am using Mongoose and I have a model called Post. I tried to run: db.post.find() in the CLI, I got:

error: { "$err" : "not authorized for query on hotel.post", "code" : 16550 }

What does this mean? Am I not authorized; I thought I connected successfully?

Updated

I upgraded my mongo shell to the latest, 2.4.x version and still I'm getting this problem. Anyone have any experience with nodejitsu & mongolab?

Mark
  • 2,137
  • 4
  • 27
  • 42
  • Well, are you authenticating? `mongo --username example` – ceejayoz Jul 12 '13 at 17:16
  • Yes I am authenticating. I updated my question and as you can see, I connected to mongo using the output of the `jitsu databases get myDB` command – Mark Jul 12 '13 at 21:43
  • 1
    Can you try running "show collections" instead? The "show dbs" command requires admin database privileges. If you are still having trouble, please don't hesitate to email support@mongolab.com so that we can help you sort this out asap! – angela Jul 14 '13 at 12:17

4 Answers4

4

MongoLab creates databases that require an authenticated user to access. When you connect with the Shell, you will need to provide the UserName and Password to the shell command. Docs are here.

mongo --username Mark --password something

You will need that Username/Password combination to be configured within mongoose as well. The Mongoose docs have details on the possible ways to do this.

Note that you are using a very old shell. 1.8.3 is about 4 versions back from the current 2.4.* line. This is not directly related to your problem, but it's definitely something you should rectify going forward.

Gates VP
  • 44,957
  • 11
  • 105
  • 108
  • 1
    In most cases you should omit `--password something` so it prompts you. If you include the password it's going to show up to other users on the server in the process list while you're using it. – ceejayoz Jul 12 '13 at 17:49
  • Hold on, other users have access to the process list with MongoLab? Why would they need that? Isn't this DBaaS? – Gates VP Jul 12 '13 at 21:04
  • Again, 'most cases', and it's a good practice to get used to so you don't inadvertently expose your credentials when you're SSHed into some shared host at some point. – ceejayoz Jul 12 '13 at 21:06
  • Is anyone using nodejitsu here? Because if you are, when you use the jitsu databases get myDB command, you will obtain the command to run in your command line that connects you to mongodb on the nodejitsu instance where by the mongodb instance (on nodejitsu) is provided by MongoLab. I'm doing exactly that (yes I did enter the password), and I still get unauthorized... – Mark Jul 12 '13 at 21:35
  • I'd contact MongoLab, then. Perhaps it's a simple misconfiguration on their end. – ceejayoz Jul 12 '13 at 22:33
3

Inside the mongo shell try to authenticate once again:

db.auth('yourUsername','yourPassword');

Alvaro
  • 39
  • 2
0

One possible error could be like me : Using special chars in the password breaks the URI!

The generated password was

X/apm~nq5JaJ,5

So OBVIOUSLY, the / broke the request and I got :

MongoError: not authorized for query on apm~nq5JaJ.system.indexes
Alexis Paques
  • 1,885
  • 15
  • 29
0

You can try to include at the end of your URI: ?authMode=scram-sha1

felipekm
  • 2,820
  • 5
  • 32
  • 42