Search code examples
node.jsmlabnodejitsu

Unable to query mongolab mongodb


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?


Solution

  • 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.