存储架构

Unable to query mongolab mongodb

微信扫一扫,分享到朋友圈

Unable to query mongolab mongodb
0

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?

Problem courtesy of: Mark

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.

Solution courtesy of: Gates VP

Discussion

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

Discussion courtesy of: Alexis Paques

Inside the mongo shell try to authenticate once again:

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

Discussion courtesy of: Alvaro

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

Discussion courtesy of: felipekm

This recipe can be found in it’s original form on Stack Over Flow
.

阅读原文...


Node.js Recipes

MySQL中ORDER BY与LIMIT一起使用(有坑)

上一篇

怎样才能构建优秀的React组件?

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Unable to query mongolab mongodb

长按储存图像,分享给朋友