How to enable the oplog on Ubuntu MongoDB for Meteor
15 Aug 2016

If you install MongoDB from Ubuntu 14.04 LTS, there’s a few steps that you need to take to enable the oplog for use with Meteor.

To enable the oplog, we need to enable replication. We’re not actually going to replicate to any other servers.

1. Enable oplog

In /etc/mongodb.conf, add

replSet = rs0

Restart mongodb:

service mongodb restart

As root, run mongo to get a shell. Run:

rs.initiate({_id:"rs0", members: [{"_id":1, "host":"127.0.0.1:27017"}]})

You should see something like:

{
        "info" : "Config now saved locally.  Should come online in about a minute.",
        "ok" : 1
}

You can run rs.conf() and rs.status() for more information.

2. Add a user to access the oplog

Switch to the admin database with:

rs0:PRIMARY> use admin

then create the user:

rs0:PRIMARY> db.addUser({user: "oplogger", pwd: "password", roles: [], otherDBRoles: {local: ["read"]}})

3. Tweak your Meteor config to use the oplog

In your Meteor environment settings, add:

MONGO_OPLOG_URL=mongodb://oplogger:[email protected]/local?authSource=admin

If you’re using my setup with Meteor running in Docker containers on AWS machines, you need to use the host IP like so:

MONGO_OPLOG_URL=mongodb://oplogger:[email protected]/local?authSource=admin

Note that you must use the local database, not whatever your application is configured for. Also note that this has security implications if you intend run separate applications on the same database server.

4. Restart your Meteor application

It it comes up without errors, that’s a really good sign!

5. Confirm that the oplog is being used

There’s some advice at https://github.com/meteor/docs/blob/version-NEXT/long-form/oplog-observe-driver.md but it’s pretty old and requires you to change your application. To be continued!


comments powered by Disqus