Just wondering about the best way to subscribe to my CouchDB data store, so that if a document in couch is updated, the KO view will also update (automagically). Is this something that's even possible?
Below is what I have so far, which simply get the user name from the user_info document.
$.getJSON('http://localhost/couchdb/user_info', function(data) {
var viewModel = ko.mapping.fromJS(data);
ko.applyBindings(viewModel);
});
Any help would be greatly appreciated!
CouchDB supports notifications when documents change: the changes feed.
You can poll the changes feed, with a ?since=X
parameter to receive only updates since X.
You can also "long poll" the feed by adding &feed=longpoll
. If there are no changes yet, CouchDB will receive your query but not answer until finally a change comes on.
Or, you can have a full COMET-style feed by instead adding &feed=continuous
. That is similar to longpoll, however CouchDB will never close the connection. Every time a change happens, it will send you the JSON and then continue waiting.
Finally, you can be notified when anything changes in the database, or you can specify a Javascript filter to run on the server (&filter=designdoc/filtername
). You will only receive notifications if the filter approves.
Have you looked at http://hood.ie/ it woks well. I'm also running hoodie as an os_daemons service from within my couchdb.
It's nice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With