DEV Community

Jan Dvorak
Jan Dvorak

Posted on

Detached database for local Meteor development

This is a short tutorial on how to use Meteor with connecting to a different MongoDB database than the build-in one.

I assume that you have Meteor and MongoDB downloaded and installed.

Start your local MongoDB and create the database you want to use for your Meteor App.
If you want to use Oplog with Meteor then you will need to convert it to replica set. But for local development it might not be necessary. If you want to get into the details on this, I recommend taking the M103 course from MongoDB University.

Now that we have all of that ready we just need to let Meteor know that we want to use detached database. If you deployed to Galaxy, then you are aware of the MONGO_URL variable that is being used to connect to the DB hosting of your choice. It is the same locally, but we only put it in the command line before running Meteor like this:

MONGO_URL=mongodb://localhost:27017/my-database meteor --settings settings.json
Enter fullscreen mode Exit fullscreen mode

And that is it!

Now why would you use it when Meteor has everything pre-packaged for you?
It comes down to advance uses and making sure that you don't delete your data if you need to run meteor reset command (which might be desirable sometimes).
Another use case is for testing. You have one database that you use for work and another one which is can be re-setup every time with testing data that your automated tests can work on.
You could also use it to have a separate DB for data that you get from production so that you can debug problems locally without mixing them with your local data set.


If you like my work, please consider supporting me on GitHub Sponsors ❤️.

Top comments (0)