orchestrate-mongo
v0.1.2
Published
Pipe MongoDB changes into Orchestrate.io
Downloads
3
Readme
Orchestrate-Mongo
Pipe MongoDB changes into Orchestrate.io, to effortlessly add a search, events, and relations API.
Install
npm install -g orchestrate-mongo
Usage
var OrchestrateMongo = require('orchestrate-mongo');
var importer = new OrchestrateMongo({
orchestrate: {
api_key: 'your_orchestrate_api_key'
},
mongodb: {
port: 27017,
host: 'localhost',
username: 'bobross',
password: 'happylittletrees',
database: 'joy-of-painting'
}
});
importer.on('change.success', console.log);
Now whenever the importer successfully writes a document to Orchestrate, it will print a message.
Using as a Daemon
You can also run Orchestrate-Mongo as a daemon, so it will continue watching your MongoDB cluster autonomously. To start the web server, just do:
npm install -g orchestrate-mongo
export ORCHESTRATE_API_KEY=...
export MONGODB_HOST=...
export MONGODB_PORT=...
export MONGODB_USERNAME=...
export MONGODB_PASSWORD=...
export MONGODB_DATABASE=...
export MONGODB_COLLECTION=...
orchestrate-mongo
# Now listening to [database]
Now the importer is running on http://localhost:3000
.
Usage on Heroku
To deploy orchestrate-mongo
on Heroku, you'll need the [heroku toolbelt][]. Then:
git clone [email protected]:orchestrate-io/orchestrate-mongo.git
cd orchestrate-mongo
heroku create [app-name]
heroku config:set ORCHESTRATE_API_KEY=...
heroku config:set MONGODB_HOST=...
heroku config:set MONGODB_PORT=...
heroku config:set MONGODB_USERNAME=...
heroku config:set MONGODB_PASSWORD=...
heroku config:set MONGODB_DATABASE=...
heroku config:set MONGODB_COLLECTION=...
git push heroku master
Now your app is running on Heroku! To prevent it from idling, scale the process to use two dynos:
heroku ps:scale worker=2
Options
orchestrate-mongo
takes one argument, an options object. It takes the following arguments, and has the following defaults:
orchestrate: {
api_key: process.env.ORCHESTRATE_API_KEY
},
mongodb: {
database: process.env.MONGODB_DATABASE,
port: process.env.MONGODB_PORT || 27017,
host: process.env.MONGODB_HOST || 'localhost',
dbOpts: {
w: 1
},
format: 'raw',
convertObjectIDs: true,
onError: function (error) {
console.log('Error - MongoWatch:', (error && error.stack) || error)
},
onDebug: function () {},
username: process.env.MONGODB_USERNAME,
password: process.env.MONGODB_PASSWORD
},
collection: process.env.MONGODB_COLLECTION
You can set many of these options as environment variables, or you can pass them directly:
var OrchestrateMongo = require('orchestrate-mongo');
var importer = new OrchestrateMongo({
orchestrate: {
api_key: 'your_orchestrate_api_key'
},
mongodb: {
port: 27017,
host: 'localhost',
username: 'bobross',
password: 'happylittletrees'
}
});
Events
connect
change
: Emitted whenever processing a change starts, succeeded, and errors out.change.start
: Detected a change in MongoDB.change.success
: Writing a document to Orchestrate.io succeeded!change.error
: Writing a document to Orchestrate.io failed due to an error.error
: The connection to MongoDB experienced an error.drain
: The queue has run out of changes to process.
Tests
First, start MongoDB like this:
sudo mongod --replSet someArbitraryName
Then, in the mongo
console, run this:
rs.initiate()
Then, set your environment variables:
export MONGODB_COLLECTION=update_operators
export MONGODB_DATABASE=orchestrate-mongodb
export ORCHESTRATE_API_KEY=YOUR_ORCHESTRATE_API_KEY
And finally, run your tests!
npm test
License
ISC, yo.