JoeTidee
JoeTidee

Reputation: 26044

MONGO_URL not being picked up by Meteor app

I have a Meteor app. and before running it I set the MONGO_URL like this:

MONGO_URL="mongodb://127.0.0.1:3001/my-db"

I echo the env var to make sure it has taken using:

echo $MONGO_URL

and all is good. Anyway, when I then run:

sudo meteor run

the app. starts, with no errors, but the database that it is connecting to is not the 'my-db' database - it is connecting to the default 'meteor' database! How is this happening when I am explicitly setting the MONGO_URL beforehand?

Upvotes: 0

Views: 475

Answers (2)

declension
declension

Reputation: 4185

The problem is you've defined it for your user's process, and not root's.

Either use sudo -E to pass through your environment [variables], or run meteor and your script as the same user (related: why are you running it as root anyway? Probably not a good idea unless you're forced to)

Upvotes: 2

David Weldon
David Weldon

Reputation: 64312

You need to do one of two things:

use the variable inline

$ MONGO_URL="mongodb://127.0.0.1:3001/my-db" meteor

export the variable

$ export MONGO_URL="mongodb://127.0.0.1:3001/my-db"
$ meteor

An export is required in the latter case so the variable will be available to the subprocess.

Upvotes: 2

Related Questions