LoginSignup
6
6

More than 5 years have passed since last update.

mongoDBにコネクトできないときの対処法

Last updated at Posted at 2016-03-11

チャットアプリを作る上でnode.jsでmondoDBを使うことにしました。ですが使い方がわからなくエラーも出て1時間くらい躓いてしまってググったのですが日本語で書いてある対処法しても解決しなかったです。
アンインストールして再インストールしてっていうの何回かしたんですけど全然だめでした。英語で書いてあるやつを試したらあっさりできたので備忘録ついでに日本語で書いておきたいと思います。

warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused

Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed 
at src/mongo/shell/mongo.js:146

のようなエラーが出たときの対処法

#手順

##/data/dbを作成する

$ mkdir -p /data/db

上記のコマンドを実行して/data/dbを作成します。

##mongoDBを起動する

$ sudo mongod

管理者としてmongodコマンドを使います。
そうするとmongoDBが起動します。
ここで初期設定で、ローカルなら http://127.0.0.1:27017 にアクセスします。

It looks like you are trying to access MongoDB over HTTP on the native driver port.

と表示されると思います。

##monge shellを起動する

$ mongo

上記のコマンドでmongo shellを起動します。

##参考にしたサイト
http://stackoverflow.com/questions/23439343/cannot-connect-to-mongodb-errno61

これで解決できなかったらすみません。
僕はこの手順でエラーを回避することができました。

6
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6