简体   繁体   中英

Meteor App not able to connect to MongoDB?

I am trying to run the meteor application on windows. I have local mongodb running on my machine and I have also set the environment variable <b>MONGO_URL=mongodb://127.0.0.1:27017/sample</b> on my system. Still meteor application is not able to connect to it. what could be the issue.

Below is the error:-

C:\workspace\node-workspace\gm>meteor
[[[[[ C:\workspace\node-workspace\gm ]]]]]

=> `Meteor server running on: <b>http://127.0.0.1:3000/</b>`

app/packages/mongo-livedata/mongo_driver.js:113
      throw err;
            ^
Error: failed to connect to [127.0.0.1:3002]
    at Server.connect.connectionPool.on.server._serverState (C:\Program Files (x86)\Meteor\packages\mongo-livedata\.npm\node_modules\mongodb\lib\mongo
db\connection\server.js:564:74)
    at EventEmitter.emit (events.js:126:20)
    at connection.on._self._poolState (C:\Program Files (x86)\Meteor\packages\mongo-livedata\.npm\node_modules\mongodb\lib\mongodb\connection\connecti
on_pool.js:124:15)
    at EventEmitter.emit (events.js:99:17)
    at Socket.errorHandler (C:\Program Files (x86)\Meteor\packages\mongo-livedata\.npm\node_modules\mongodb\lib\mongodb\connection\connection.js:465:1
0)
    at Socket.EventEmitter.emit (events.js:96:17)
    at Socket._destroy.self.errorEmitted (net.js:329:14)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)
=> Exited with code: 1
=> Meteor server restarted

app/packages/mongo-livedata/mongo_driver.js:113
      throw err;
            ^
Error: failed to connect to [127.0.0.1:3002]
    at Server.connect.connectionPool.on.server._serverState (C:\Program Files (x86)\Meteor\packages\mongo-livedata\.npm\node_modules\mongodb\lib\mongo
db\connection\server.js:564:74)
    at EventEmitter.emit (events.js:126:20)
    at connection.on._self._poolState (C:\Program Files (x86)\Meteor\packages\mongo-livedata\.npm\node_modules\mongodb\lib\mongodb\connection\connecti
on_pool.js:124:15)
    at EventEmitter.emit (events.js:99:17)
    at Socket.errorHandler (C:\Program Files (x86)\Meteor\packages\mongo-livedata\.npm\node_modules\mongodb\lib\mongodb\connection\connection.js:465:1
0)
    at Socket.EventEmitter.emit (events.js:96:17)
    at Socket._destroy.self.errorEmitted (net.js:329:14)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)
=> Exited with code: 1
=> Meteor server restarted

app/packages/mongo-livedata/mongo_driver.js:113
      throw err;
            ^
Error: failed to connect to [127.0.0.1:3002]
    at Server.connect.connectionPool.on.server._serverState (C:\Program Files (x86)\Meteor\packages\mongo-livedata\.npm\node_modules\mongodb\lib\mongo
db\connection\server.js:564:74)
    at EventEmitter.emit (events.js:126:20)
    at connection.on._self._poolState (C:\Program Files (x86)\Meteor\packages\mongo-livedata\.npm\node_modules\mongodb\lib\mongodb\connection\connecti
on_pool.js:124:15)
    at EventEmitter.emit (events.js:99:17)
    at Socket.errorHandler (C:\Program Files (x86)\Meteor\packages\mongo-livedata\.npm\node_modules\mongodb\lib\mongodb\connection\connection.js:465:1
0)
    at Socket.EventEmitter.emit (events.js:96:17)
    at Socket._destroy.self.errorEmitted (net.js:329:14)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.

Given that the stack trace says that meteor is still trying to connect to the mongoDb instance on port 3002, then either you have't set the environment variable properly or you haven't reloaded the cmd shell to get the new value.

How did you set MONGO_URL ? If you set it through the System Properties or updated the autoexec.bat then you'll need to re-load the cmd shell.

You can see what the current value is by typing in the cmd shell:

echo %MONGO_URL%

Then to set it for the current env you can do :

set MONGO_URL=mongodb://127.0.0.1:27017/sample

I know it's been awhile but I ran into this same issue (in July 13') I didn't have time to figure it out and ended up going to a Linux installation which worked fine.

Recently however I got some time to circle back to it. Here is some discussion on the matter in the google group- https://groups.google.com/forum/#!topic/meteor-talk/AE6GYrJImAo

I found out that the Mongo DB process was not even starting, some conflict within mongo_runner.js ... My solution was to start mongo manually

C:\Program Files (x86)\Meteor\mongodb\bin>mongod -port 3002 --dbpath C:\Users\username\project\.meteor\local\db

The above starts the project on the needed port and specifies the database folder for your project... After this just start meteor as you normally would.

As of Version 0.7.1 the meteor mongodb port is 3001, instead of 3002.

The port is generally 1 higher (2 in the case of older versions of meteor) than the port Meteor is running on. eg if Meteor runs on port 3000, MongoDB would be at port 3001

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM