As described in my previous post, I needed to use a custom MongoDB installation on my server since I could not access the Meteor MongoDB from an external server. Here is how I setup Meteor to work with this database.
I stumbled on this post on StackOverflow. It turned out you can the environment variable MONGO_URL which you could point to your MongoDB installation.
export MONGO_URL='mongodb://user:[email protected]:12345/'
You can check if the variable was correctly set by:
If you want to go back to the default behaviour where Meteor uses its own MongoDB. You need to unset the MONGO_URL environment variable
Using this I made a stupid mistake. I used two terminals one to run Meteor and one to check the database. When you have two terminals and you set an environment variable in one of them you need to restart the other one to see the newly set variable. I forgot about this and it took some time to figure out why this wasn’t working.
Now I start my project with this command:
MONGO_URL='mongodb://user:[email protected]:12345/' meteor
When you view your database after the first run you see nothing there yet. I was looking for the meteor database to be there, but it wasn’t. Meteor does not create this database if there is no data to write yet. Therefore you need to write some data to a collection to see if Meteor is connecting to the right MongoDB.
In order to check the content of the MongoDB I started the mongo command which connected me to the running MongoDB instance with just running:
Then I needed to select the meteor database:
Check which collections are in the meteor database:
Check the contents of the meteor collection