Meteor 1.4, MongoDB and Compose - Ready to Oplog


With a switch to newer MongoDB drivers and other low level improvements, the new Meteor 1.4 works much better with Compose's MongoDB. That means that we now recommend that users migrate to Meteor 1.4 to get the best performance and reliability with their Compose databases.

Meteor 1.4 has two major improvements. Firstly it can use Compose's default connection strings which specify two addresses for database connections. Updated Node MongoDB drivers now correctly parse the connection string which, in turn, means it can make use of both access portals for failover.

The other improvement is that change-streaming Oplog connections are now far more reliable, again thanks to the updated Node MongoDB drivers in Meteor 1.4. Before we move on to talk about that, we'd like to remind you that the use of the Oplog may not be ideal for all Meteor applications.

To Oplog or not Oplog

The question of whether or not you want to enable the Oplog is still a question for Meteor application developers to answer for themselves. As we discussed in Connecting to the Oplog on the new MongoDB there are application architecture issues to bear in mind.

The number of meteor servers and actual speed and quantity of updates needed between those servers has an impact on overall performance. If your users are, for example, not collaborating on the same forms or documents then the constant stream of updates when the Oplog is in use from other database changes may use more resources in your Meteor servers than the users using those servers.

The good news is that use of the Oplog is entirely determined by the presence of one environment variable so it is easy to switch between oplog and non-oplog use. So let's look at configuring the new Meteor and Compose.

Configuring Meteor 1.4 and Compose MongoDB

Without Oplog

As with all Compose databases, the process of connecting begins with a Compose connection string, which you'll find on the console for your Compose deployment. It looks like this:


This is the global connect string and as such it shows how to connect to the admin database which is always going to exist (as it stores the user credentials among other things). Note the admin at the end before the ?ssl=true (unless you've created your database without SSL enabled). Replace the admin with the name of the database you want to lookup if you want to quickly create a string for that database.

The <username> and <password> will, of course, need to be replaced too, but remember that if you will need to use a username that has been given access to whichever database you are using. Creating a user for a database is handled through the database browser which you can get by selecting Browser in the left hand sidebar. In the browser, select the database to view the options specific to that database. You can then select Users in the left hand side bar. You can also select Admin to view the connection strings and statistics for that particular database.

Once you have your connection string, go to your Meteor application and, before starting it, set the environment variable MONGO_URL to the connection string. For example, if we have a database called "blacklist" with a user "reddington" and password "xyzzy" this would come out as

$ export MONOGO_URL=mongodb://,

Now start your Meteor application. The Meteor server will now use polling to check for updates to the database server by other Meteor servers.

With Oplog

Meteor requires an environment variable, MONGO_OPLOG_URL, to be set to enable the Oplog. MongoDB on Compose uses an add-on to give access to the Oplog. You need only one Oplog addon for a MongoDB deployment; all changes from all databases in the deployment are reflected in the Oplog. To add an add-on select Add-ons from the left-hand side bar. This takes you to the Add-on page for all add-ons:


Click Add on the Oplog Access panel, which will take you to the confirmation page:

Oplog Acess Confirm

We recommend you leave SSL enabled and note the cost ($4.50 per month) of having the oplog Access Add-on installed. Click on Add MongoDB Oplog Access and the process will begin. You'll be taken to the Jobs screen where the progress of installing the add-on is displayed. It's a quick addition, so click on Add-Ons in the sidebar again and you should see the same add-on list, but now the Oplog Access add-on displays Configure. Click on that button to see something like this:

Oplog Access Config1

This screen shows you the user name for the oplog user in the database (you do not need to create an oplog user), an obscured password for that account, a connection string for Oplog using applications to use, a command line to be used when debugging and a button to reveal an SSL certificate.

To get the full connection string, click on the show button next to the password. If you haven't re-authenticated recently, you will be prompted for your account password. Once entered the display will look like this:

Oplog Access Config2

You can now copy the entire Connection String for the router as the value for the MONGO_OPLOG_URL, like so:

$ export MONGO_OPLOG_URL="mongodb://"

Note that the entire connection string is wrapped in double quotes to stop the shell from interpreting the ampersand towards the end as an instruction to end the line.

With this and MONGO_URL set, you can now start your Meteor server and it will use the Oplog to identify updates from the database made by other Meteor servers.


Now you can update to the SSL-enabled Compose MongoDB and make use of our dual HAProxy/MongoS routers for resilient connections to the database using Meteor. In the future we'll be looking at the options afforded by the new Mongo.setConnectionOptions(options) function. Till then, why not sign up for a free 30 day Compose trial, spin up a new Compose MongoDB today and try out Meteor 1.4 with it?

Dj Walker-Morgan
Dj Walker-Morgan was Compose's resident Content Curator, and has been both a developer and writer since Apples came in II flavors and Commodores had Pets. Love this article? Head over to Dj Walker-Morgan’s author page to keep reading.

Conquer the Data Layer

Spend your time developing apps, not managing databases.