A Node.js package that provides high availability for Monk, the wise MongoDB API. It implements smart error handling and retry logic to handle temporary network connectivity issues and replica set step-downs seamlessly.
bufferMaxEntriesis correctly configured
First, install the package using npm:
npm install monkster --save
monkster and wrap your collections with it, as demonstrated here:
var monk = ;var monkster = ;// Initialize Monk with your MongoDB connection stringvar db = ;// Initialize Monkster and customize its error handling behaviorvar wrap =;// Wrap your collections with monkstervar logs = ;var users = ;
Finally, invoke your queries as you are used to -- Monkster will take care of the error handling and retry logic for you. Feel free to use ES6 generators to achieve this.
try// Insert a document into the collection (with generators)users;catch err// Query failed for more than "maxTries" number of tries// Count number of documents in the collection (with promises)var count = users;
examples/basic.js for a more complete example.
Monkster supports the following configuration, passed in when invoking
var options =// If a query fails more than X times, give up on itmaxTries: 60// Number of milliseconds to wait before retrying a failed queryretryInterval: 1000var wrap = ;