Can't connect to remote mongo DB - Is it even possible?

I’m trying to connect to a remote db on mLabs, my development server is on local machine. I try to connect like this but no connection is made at all.

Meteor.startup(function () {
    process.env.MONGO_URL = "mongodb://";

This is located in the server.js file in the server directory of the app.

How else can I connect to the app?

Or does Meteor not connect to external databases?

It definitely can - try specifying your MONGO_URL as an environment variable before launching meteor. So something like:

MONGO_URL="some url" meteor

I thought doing it in Meteor.startup would launch it? Where else could I launch it?

Meteor needs the MONGO_URL to be defined before startup functions are called via Meteor.startup. You should define your MONGO_URL environment variable before starting Meteor. If you’re using Linux/OSX for example, you can just specify it before the meteor command, on your command line. So on the same line in your console, just type in the full line I listed above (substituting in your proper MONGO_URL).

So I try to run it as that:

MONGO_URL="mongodb://" meteor --settings settings.json

It gives the error:

'MONGO_URL' is not recognized as an internal or external command, operable program or batch file.

Which means you’re using Windows :slight_smile: . In that case:

set MONGO_URL="some url"
1 Like

Thanks but

set MONGO_URL="mongodb://" meteor --settings settings.json

does nothing now…it doesn’t start the server up

Since you’re using Windows, run the set MONGO_URL="..." part first to set the environment variable, then after that’s done call meteor on a separate line in your console.

1 Like

Just to add to this, you may need to remove the quotes around the URL on the set command. Windows can be somewhat literal and I recall getting involved in a post where the quotes were being passed as part of the data.


Thanks guys that has worked and I did need to remove the quotes on Windows.

set MONGO_URL=mongodb:// meteor --settings settings.json

Many thanks once again



Is this also the best practice for production ?

P.S. : Sorry for replying to a thread after 2 years lol

I’m using Windows, and use these commands without the quotes "" worked for me. Thank you.

Depends on where your app will be hosted, if you’re deploying to Galaxy, you set it in your settings.json file.