Help us understand the problem. What is going on with this article?

HerokuのMongodbを直接操作する(Monglab編)

More than 3 years have passed since last update.

ポスグレでやったようにMongodbを直接操作する。

接続URLを取得して読み解く

heroku config | grep MONGOLAB_URI

mongodb://ではじまるURLが取得できるのでURLから情報を抜く。

mongodb://<接続ユーザー>:<パスワード>@<ホスト名>:<ポート>/<DB名>

ターミナルから接続してみる

mongo <ホスト名>:<ポート>/<DB名>
MongoDB shell version: 3.0.6
connecting to: <ホスト名>:<ポート>/<DB名>

つながった。適当にmongoのコマンドを打ってみる。

db.posts.count()
2015-10-02T16:13:31.231+0900 E QUERY    Error: count failed: {
    "ok" : 0,
    "errmsg" : "not authorized on <DB名> to execute command { count: \"posts\", query: {}, fields: {} }",
    "code" : 13
}
    at Error (<anonymous>)
    at DBQuery.count (src/mongo/shell/query.js:326:11)
    at DBCollection.count (src/mongo/shell/collection.js:1046:27)
    at (shell):1:10 at src/mongo/shell/query.js:326

認証しないとダメみたい。

db.auth("<接続ユーザー>","<パスワード>")

1が返ってくればOK。もう一度試してみる。

db.posts.count()
0

接続できました。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away