本地的MongoDB无法启动
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: 无SQL数据库。
$ 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 # 自動起動しているもの一覧