Skip to content

Streams changes from a CouchDB and emits them as events

License

Notifications You must be signed in to change notification settings

sl45sms/couchstream

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Subscribes to CouchDB's change feed and emits the JSON objects.

Usage

new CouchStream({
    database: 'recipes',
    query: {
        since: 50,
        heartbeat: 10000,
        filter: 'app/blueberries',
        vegetarian: true
    }
}).on('change', function(change) {
    console.warn(change);
});

All parameters except for database are optional. All unrecognized query parameters are passed along so that CouchDB filter functions can use them.

You can also supply a filter as a plain JavaScript function. CouchStream will create a filter design document on the server and use that filter to retrieve the changes. Make sure that you don't reference any variables outside that function; they won't be available on the CouchDB server.

new CouchStream({
    database: 'recipes',
    query: {
        since: 50,
        filter: function(doc, req) {
            return doc.type == 'recipe' &&
                   doc.ingredients.indexOf('Coconut') >= 0;
        }
    }
}).on('change', function(change) {
    console.warn(change);
});

About

Streams changes from a CouchDB and emits them as events

Resources

License

Stars

Watchers

Forks

Packages

No packages published