MongoDB is alright. With an expansive, SQL-like query and update syntax, it handles most small-time use cases with relative ease and little forethought. But, MongoDB falls over under various circumstances. To keep it from stalling your apps, crashing for want of memory, losing data, and so on, you need to become a DBA. Come on, we’re here to build apps. Databases are details.

We’ve written about transitioning from MongoDB before. The process outlined there moves data, but doesn’t keep data synced. It’s good if you’re transitioning away from MongoDB entirely, but what if you want to play with Orchestrate using live data, but without migrating live systems? We got you.

To continually replicate a MongoDB collection into an Orchestrate one, I wrote orchestrate-mongo. It uses MongoDB’s oplog to indefinitely watch a MongoDB collection and play back any changes onto a collection in Orchestrate, keeping the two in sync so long as the process is running. This is handy if you’re using MongoDB for something currently and want to give Orchestrate a try with existing data, but don’t want to transition where your apps put their data before you play around for a bit. In fewer words, orchestrate-mongo provides an effortless trial and transition path from MongoDB to Orchestrate.

So how do you sync from MongoDB to Orchestrate? The key is in activating a replication set in MongoDB, so you can get access to the replication log that orchestrate-mongo uses to watch MongoDB for changes. To kick up a replication set, start mongod with the --replSet option, like this:

sudo mongod --replSet someArbitraryName

Then, initiate the replication set with rs.initiate() in the MongoDB console, like this:

sudo mongo # starts up the mongodb console
> rs.initiate()

Now, set your environment variables:

export ORCHESTRATE_API_KEY=...
export MONGODB_HOST=...
export MONGODB_PORT=...
export MONGODB_USERNAME=...
export MONGODB_PASSWORD=...
export MONGODB_DATABASE=...
export MONGODB_COLLECTION=...

These values inform orchestrate-mongo where and how to access MongoDB and Orchestrate and which collection to sync.

Once you’ve set the environment variables, install and start orchestrate-mongo like this:

npm install -g orchestrate-mongo
orchestrate-mongo
# Now listening to [database]

Now you’re syncing changes from MongoDB to Orchestrate! Nice going. The process will continue until you kill it manually.

orchestrate-mongo is still under heavy development, but has been tested successfully against MongoDB 2.6. If you want to file a bug or get involved, check the project’s issues page.

Happy coding!