How to connect to an external instance of MongoDB in Meteor?

I would like to learn how to connect to an external instance of MongoDB in Meteor.

I added this environment

Meteor.startup(function () { process.env.MONGO_URL = 'mongodb://[UN]:PW]@[host]:[port]/meteorTest' }); 

but still the data comes from the local database.

I want to move all collections from my local db to this external db. I read all the tutorials, all this tells me that I am setting up this evn variable, but nothing really works. How to check if it is connected or not?

+5
source share
3 answers

In my own experience; I need to set an environment variable before running the meteorjs server application. To do this, you will need to pass the environment variable on the command line when you call the meteor or pre-set the environment for the profile on which the meteorite application is running on your system.

So, you should launch your application with the following command:

 MONGO_URL='mongodb://user: password@remote.domain.com :12345/' meteor 

You must also ensure that mongodb is available and that your user credentials are correct! I assume that you are trying to run meteor on your local machine using a remote mongodb instance.

In windows

You will need to create a batch file in the meteorite application folder to invoke the environment variable. Here is an example of this: fooobar.com/questions/1254033 / ...

+15
source

I do not like to use a large repeating command, and I was looking for a solution in which I will set a variable embedded in something, so every time I launch my meteorite application; MONGO_URL will automatically set the environment. So here is what I did:

In the package.json file, I replaced the initial parameter as follows:

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

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

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

+3
source

run it on the command line:

  "MONGO_URL=mongodb://<USER>:<PASSWORD>@<SERVER>:<PORT>/<DB> meteor" 

or save this url in the run.sh file in the project folder and run meteor

0
source

All Articles