简体   繁体   中英

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?

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.

在mongo shell内,尝试再次进行身份验证:

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

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

您可以尝试在URI的末尾添加: ?authMode=scram-sha1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM