alste
alste

Reputation: 1455

How do you programmatically set MONGO_URL?

How do I set MONGO_URL from within my Meteor app?

I tried

process.env.MONGO_URL = '...'

in my server-side code, outside Meteor.startup, but that isn't working.

I'm using demeteorizer to bundle it into a node.js app. I can't set MONGO_URL in Terminal directly (I'm running my app on a third-party provider).

Upvotes: 1

Views: 2696

Answers (2)

jonperl
jonperl

Reputation: 891

You can overwrite the default collection driver

MongoInternals.defaultRemoteCollectionDriver = _.once(function () {
  return new MongoInternals.RemoteCollectionDriver(Meteor.settings.MONGO_URL, {
    oplogUrl: Meteor.settings.MONGO_OPLOG_URL
  });
});

or set it manually per collection

var database = new MongoInternals.RemoteCollectionDriver(Meteor.settings.MONGO_URL, {
  oplogUrl: Meteor.settings.MONGO_OPLOG_URL
});

somecollection = new Mongo.Collection('somecollection', {_driver: database});

Upvotes: 2

Julien Le Coupanec
Julien Le Coupanec

Reputation: 7988

From Meteorpedia: Environment Variables.

Setting the value of an Environment Variable

The safest time to do this with guaranteed behaviour for any variable is BEFORE METEOR STARTS. This is usually done either through your PaaS provider's control panel for your app, or in the shell script that launches Meteor, e.g.

IMPORTANT: You can also set/change an environment variable from inside Meteor, but you need to set it before it's used. e.g. it's too late to set MONGO_URL after Meteor has been loaded, but MAIL_URL is ok since you'll get it set before any mail is sent.

Upvotes: 2

Related Questions