MongoDB / Meteor / Export MONGO_URL to deployed applications

11,709

Solution 1

You are not able to use your own MONGO_URL with Meteor deploy hosting.

Meteor deploy hosting takes care of the Email with Mailgun (if you use it), and provides mongodb for all apps deployed there.

It is possible to change the MAIL_URL, but it is not possible to use a different mongodb.

You can try, though im not sure it will work:

Place this in your server side code somewhere

process.env.MONGO_URL = '..';

Solution 2

Create a lib folder under the server folder and write:

Meteor.settings = { //your settings };

According to documentation everything inside a folder named lib will be executed before anything, so this way we ensure that no code will be execute before this, preventing errors from accessing Metrics that don't exist.

If you're already using the lib folder you've to named right to run before anything else that might conflict, check the docs about it.

Enjoy.

Solution 3

The application-configuration package (built in meteor package) contains the code to set mongo_url. See my answer here https://stackoverflow.com/a/23485319/2391620

Share:
11,709
Samsy
Author by

Samsy

Updated on June 16, 2022

Comments

  • Samsy
    Samsy almost 2 years

    I tried to export a settings.json as documented in the meteor.js documentation in order to connect my Meteor.js app with an external MongoHQ database :

    {
        "env": {
            "MONGO_URL" : "mongodb://xxx:[email protected]:10037/xxx"
        }
    }
    

    with the command :

    mrt deploy myapp.meteor.com --settings settings.json
    

    It doesn't even work, My app continue to connect the local database provided with the Meteor.app ! My MONGO_URL env variable didnt changed.

    Is there any solution to export my MONGO_URL env variable to connect an external MongoDB database ?

    I saw that is possible to change it while using heroku or modulus, what about the standard deploying meteor.com solution ?

  • Samsy
    Samsy about 10 years
    I already try to set it like this manually top of my server.js file, before the server startup..
  • Tarang
    Tarang about 10 years
    Yup it looks like its not possible. If you want to use your own mongo db you would have to host it yourself
  • Alexander Mills
    Alexander Mills about 9 years
    is there a way to shell into your mongo shell on meteor.com?
  • JoeTidee
    JoeTidee about 9 years
    Surely the connection to the database needs to happen before Meteor even starts (?)
  • Mário
    Mário about 9 years
    Yes, it needs. This hack works for me because I store API Keys and I want to use my dev config file in *.meteor.com
  • Lukasstr
    Lukasstr over 8 years
    could u please post an example how to use the process.env variable this method?