[Solved] Connect to external MongoDB database from MeteorJs application on Windows

Hopefully this is a newbie question.
I am trying to connect to an external MongoDB database from MeteorJs application on Windows. I am however getting a “Authentication failed” error. I have set the Env:MONGO_URL using powershell and I am then running the meteor command on the command prompt. I am however able to connect to the same database using a client tool(Studio 3T)

$Env:MONGO_URL=‘mongodb://:@/’

What am I missing?

W20190915-18:32:25.554(-5)? (STDERR) C:\Users\AjitGoel\AppData\Local.meteor\packages\meteor-tool\1.8.1\mt-os.windows.x86_64\dev_bundle\server-lib\node_modules\fibers\future.js:313
W20190915-18:32:25.557(-5)? (STDERR) throw(ex);
W20190915-18:32:25.560(-5)? (STDERR) ^
W20190915-18:32:25.564(-5)? (STDERR)
W20190915-18:32:25.569(-5)? (STDERR) MongoError: Authentication failed.
W20190915-18:32:25.571(-5)? (STDERR) at C:\Users\AjitGoel\AppData\Local.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb-core\lib\connection\pool.js:581:63
W20190915-18:32:25.574(-5)? (STDERR) at authenticateStragglers (C:\Users\AjitGoel\AppData\Local.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb-core\lib\connection\pool.js:504:16)
W20190915-18:32:25.578(-5)? (STDERR) at Connection.messageHandler (C:\Users\AjitGoel\AppData\Local.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb-core\lib\connection\pool.js:540:5)
W20190915-18:32:25.580(-5)? (STDERR) at emitMessageHandler (C:\Users\AjitGoel\AppData\Local.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb-core\lib\connection\connection.js:310:10)
W20190915-18:32:25.584(-5)? (STDERR) at Socket. (C:\Users\AjitGoel\AppData\Local.meteor\packages\npm-mongo\3.1.2\npm\node_modules\mongodb-core\lib\connection\connection.js:453:17)
W20190915-18:32:25.588(-5)? (STDERR) at emitOne (events.js:116:13)
W20190915-18:32:25.590(-5)? (STDERR) at Socket.emit (events.js:211:7)
W20190915-18:32:25.594(-5)? (STDERR) at addChunk (_stream_readable.js:263:12)
W20190915-18:32:25.598(-5)? (STDERR) at readableAddChunk (_stream_readable.js:250:11)
W20190915-18:32:25.600(-5)? (STDERR) at Socket.Readable.push (_stream_readable.js:208:10)
W20190915-18:32:25.602(-5)? (STDERR) at TCP.onread (net.js:601:20)
=> Exited with code: 1

Looks like it’s connecting to mongo, but mongo is rejecting the connection as it doesn’t pass auth.
You likely need to pass the user and password in the connection string (or if you are partially including it, try omitting it entirely)

Thank you @coagmano.

I am passing the user ID and password (along with the host and database name). I am using the same for querying using a client tool. I will try creating a new user ID and try with that in Windows.
Is the process different on a Linux server? I am asking as I was reading that I need to add my host ip address to mongod.conf file, under allowable up address that can connect to the mongodb instance.

Process should be the same, as I believe it uses TCP anyway.

Is it on the same PC as Meteor (localhost)?

The external mongodb database is on mlab.com, not on my local machine.

I am getting the same issue connecting from my digital ocean Linux machine to mongodb hosted on mlab.com.

Just tried it afer creating a brand new user. I am able to connect using a client tool but not via meteorjs application.

I was able to get it working by creating a new MONGO_URL environment variable under “system variables” instead of using Powershell to create an environment variable. Now to get the meteorjs application working on my Linux Digital Ocean VM.
Thank you @coagmano for your help.

1 Like

:tada:
This is (one reason) why I hate env vars in windows haha