Mongoose无法连接到localhost:MongoError:无法连接到服务器[127.0.0.1:27017]

时间:2016-12-02 07:12:48

标签: node.js mongodb heroku mongoose

我正在处理从Github https://github.com/MessagingBots/MessengerBot下载的回购,我知道js代码没问题。

我有一个配置文件,将db URL指向" mongodb://127.0.0.1:27017 / messenger"。 (我还没有创建数据库)

我在Heroku上有节点应用程序,但每次在mongodb connect上Heroku Logs失败。

2016-12-02T06:23:31.636339+00:00 app[web.1]: mongodb://127.0.0.1:27017/messenger
2016-12-02T06:23:31.672354+00:00 app[web.1]: CALLBACK URL IS
2016-12-02T06:23:31.672434+00:00 app[web.1]: https://cool-scrubland-89690.herokuapp.com/messages/receive/
2016-12-02T06:23:31.683394+00:00 app[web.1]: students
2016-12-02T06:23:31.701863+00:00 app[web.1]: listening on port 3124
2016-12-02T06:23:31.702052+00:00 app[web.1]: Application running at port 48594
2016-12-02T06:23:31.717752+00:00 app[web.1]: 
2016-12-02T06:23:31.717764+00:00 app[web.1]: /app/node_modules/mongoose/node_modules/mongodb/lib/server.js:261
2016-12-02T06:23:31.717766+00:00 app[web.1]:         process.nextTick(function() { throw err; })
2016-12-02T06:23:31.717767+00:00 app[web.1]:                                       ^
2016-12-02T06:23:31.718744+00:00 app[web.1]: MongoError: failed to connect to server [127.0.0.1:27017] on first connect
2016-12-02T06:23:31.718746+00:00 app[web.1]:     at Pool.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:313:35)
2016-12-02T06:23:31.718747+00:00 app[web.1]:     at emitOne (events.js:96:13)
2016-12-02T06:23:31.718747+00:00 app[web.1]:     at Pool.emit (events.js:188:7)
2016-12-02T06:23:31.718748+00:00 app[web.1]:     at Connection.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:271:12)
2016-12-02T06:23:31.718749+00:00 app[web.1]:     at Connection.g (events.js:291:16)
2016-12-02T06:23:31.718750+00:00 app[web.1]:     at emitTwo (events.js:106:13)
2016-12-02T06:23:31.718750+00:00 app[web.1]:     at Connection.emit (events.js:191:7)
2016-12-02T06:23:31.718751+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:165:49)
2016-12-02T06:23:31.718752+00:00 app[web.1]:     at Socket.g (events.js:291:16)
2016-12-02T06:23:31.718752+00:00 app[web.1]:     at emitOne (events.js:96:13)
2016-12-02T06:23:31.718753+00:00 app[web.1]:     at Socket.emit (events.js:188:7)
2016-12-02T06:23:31.718754+00:00 app[web.1]:     at emitErrorNT (net.js:1276:8)
2016-12-02T06:23:31.718754+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-12-02T06:23:31.718755+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:98:9)
2016-12-02T06:24:24.832476+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-12-02T06:24:24.832543+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-12-02T06:24:24.958931+00:00 heroku[web.1]: State changed from starting to crashed
2016-12-02T06:24:24.949820+00:00 heroku[web.1]: Process exited with status 137

我正在运行mongod个实例。 mongod正确连接到localhost并且稳定

2016-12-02T14:02:26.733+0700 I CONTROL  [initandlisten] MongoDB starting : pid=2706 port=27017 dbpath=/data/db 64-bit host=ME.local
2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] db version v3.2.11
2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] git version: 009580ad490190ba33d1c6253ebd8d91808923e4
2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016
2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] allocator: system
2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] modules: none
2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] build environment:
2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten]     distarch: x86_64
2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten]     target_arch: x86_64
2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] options: {}
2016-12-02T14:02:26.738+0700 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-12-02T14:02:26.739+0700 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=4G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-12-02T14:02:27.758+0700 I CONTROL  [initandlisten] 
2016-12-02T14:02:27.759+0700 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2016-12-02T14:02:27.763+0700 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-12-02T14:02:27.763+0700 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2016-12-02T14:02:27.767+0700 I NETWORK  [initandlisten] waiting for connections on port 27017

问题可能与猫鼬有关。

有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:1)

查看是否存在旧锁定文件(如果存在),而不是将其删除 sudo rm /var/lib/mongodb/mongod.lock看看这是否适合你 sudo mongod --repair and(sudo start mongodb或sudo service mongodb start)

答案 1 :(得分:0)

你的mongoose connect call中没有精确的mongodb://:

mongoose.connect("localhost:27017/mydbname");