12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ローカルのMongoDBが起動しない

Posted at

node.js

$ node app/app.js
listen on port 3000
MongoDB connection error: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]

MongoDB

$ mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-04-15T17:15:09.310+0900 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-04-15T17:15:09.312+0900 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed
$ sudo mongod --repair
2018-04-15T17:15:22.386+0900 I CONTROL  [initandlisten] MongoDB starting : pid=41628 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro.local
2018-04-15T17:15:22.387+0900 I CONTROL  [initandlisten] db version v3.6.3
2018-04-15T17:15:22.387+0900 I CONTROL  [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
2018-04-15T17:15:22.387+0900 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2o  27 Mar 2018
2018-04-15T17:15:22.387+0900 I CONTROL  [initandlisten] allocator: system
2018-04-15T17:15:22.387+0900 I CONTROL  [initandlisten] modules: none
2018-04-15T17:15:22.387+0900 I CONTROL  [initandlisten] build environment:
2018-04-15T17:15:22.387+0900 I CONTROL  [initandlisten]     distarch: x86_64
2018-04-15T17:15:22.387+0900 I CONTROL  [initandlisten]     target_arch: x86_64
2018-04-15T17:15:22.387+0900 I CONTROL  [initandlisten] options: { repair: true }
2018-04-15T17:15:22.388+0900 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2018-04-15T17:15:22.388+0900 I CONTROL  [initandlisten] now exiting
2018-04-15T17:15:22.388+0900 I CONTROL  [initandlisten] shutting down with code:100
$ mongod -dbpath /usr/local/var/mongodb

最終的にこれでうまくいった。

追記

後日、また起動しなくなった。
常時起動を設定することで解決できた。

$ brew services start mongodb # MongoDBを常時起動する
$ brew services stop mongodb # MongoDBの常時起動を停止する
$ brew services list # 自動起動しているもの一覧
12
12
0

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
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?