One of the most successful NoSQL database solutions, MongoDB is working on a JSON-like architecture. Combined with Mongo-Express it can kick-start your web project. Here's how to set it up on sloppy.io.
Start by creating a new project. For this tutorial I’m naming the project “my-mongo-db”. I'm going to divide it into a “backend” service for MongoDB and a “frontend” service for Mongo-Express.
First of all, we’re setting up MongoDB. Type “mongo” into the Image Path field and the first suggestion should be the official repository for MongoDB on Docker Hub, aptly named
mongo. Disable the “web app” option, since MongoDB will just work in the background.
Step 1: Selecting Docker image for MongoDB and Environment Variables
Now for some Environment Variables. By default, MongoDB doesn't need authentication. Just to be safe, we're going to add a superuser
MONGO_INITDB_ROOT_USERNAME and their password
MONGO_INITDB_ROOT_PASSWORD. Once this is done, click on “Deploy project” and wait for the service to fully load.
Next is Mongo-Express, the most common administration tool for MongoDB. Once again, typing “mongo” into the Image Path field will yield to a list of suggestions where
mongo-express should come in second. Again, this is the official release. Now, choose a subdomain for “sloppy.zone” that isn’t already taken, or set up a custom domain if you’ve already got one. For this tutorial, we’re going with “my-mongo-db.sloppy.zone”.
Step 2: Setting up Mongo-Express, domain name, and Environment Variables
Mongo-Express comes with a variety of Environment Variables for its customization. To connect Mongo-Express with our MongoDB, set a
ME_CONFIG_MONGODB_SERVER and point it towards MongoDB – in this case
mongo-db.backend.my-mongo-db. Note that sloppy.io is making it easy for you by already autosuggesting this. Next come the optional superuser
ME_CONFIG_MONGODB_ADMINUSERNAME and their password
ME_CONFIG_MONGODB_ADMINPASSWORD, which we have set for MongoDB (see above). To protect Mongo-Express from unwanted guests, we also set up a web user
ME_CONFIG_BASICAUTH_USERNAME complete with password
Step 3: Wait for both apps to run successfully
Click on “Update project” and wait for both services to load. Then click on the link on the Mongo-Express app or enter your chosen domain into your browser. Mongo-Express will ask for the web user we’ve set up earlier (not the admin user!) and that’s it: you’re ready to go.
Step 4: Login to Mongo-Express and start working
Overriding bind_ip in MongoDB 3.6+
If you're using MongoDB 3.6 or newer and you're setting the command (cmd) property to pass command-line flags, you also have to set the
bind_ip parameter to allow connections from other hosts. For example, when you're using a command to set
mongod --smallfiles --bind_ip=0.0.0.0
Here are the links to the Docker Hub images and respective Environment Variables we've been using in this tutorial:
- MongoDB: https://hub.docker.com/_/mongo/
- MongoDB Environment Variables:
- Mongo-Express: https://hub.docker.com/_/mongo-express/
- Mongo-Express Environment Variables:
Find out how to manage other databases on sloppy.io