How to connect to external MongoDB instance in Meteor?

前端 未结 3 630
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 17:06

I would like to find out how to connect to an external MongoDB instance in Meteor.

I have added this environment

Meteor.startup(function () { 
proce         


        
3条回答
  •  生来不讨喜
    2020-12-01 17:44

    I don't like to use big repeating command and I was searching for a solution where I will be setting a variable embedded with something so every time I start my meteor app; the MONGO_URL will set to environment automatically. So this what I did:

    In the package.json file I replaced the start parameter as below:

    "scripts": {
        "start": "MONGO_URL=mongodb://username:password@host_url:portnumber/dbname meteor run"
      },
    

    Now every time I want to run my app; I run npm start instead of meteor or meteor run

    Note: there is a disadvantage with that. Your db credentials will be exposed if you put your db credentials to package.json file and add this file to version control.

提交回复
热议问题