The trick is to rerun your query whenever the database changes. To do this you can connect to the _changes API via the longpoll query: http://docs.couchbase.com/couchbase-lite/cbl-api/#get-db-changes
Here is a place where I do it in code, by calling a changes API handler that I wrote. https://github.com/couchbaselabs/TodoLite-PhoneGap/blob/master/js/index.js#L59 Once I am listening to the feed, I use it to call a global function (window.onChange). My application swaps out that function depending on which view is active. If you want that module (coax) it is available on npm, or you can grab the modules.js file used by TodoLite-PhoneGap, and require it like this: https://github.com/couchbaselabs/TodoLite-PhoneGap/blob/master/js/index.js#L21 And instantiate it like this: https://github.com/couchbaselabs/TodoLite-PhoneGap/blob/master/js/index.js#L542 Here is the readme for coax: https://github.com/jchris/coax Hope that helps. On Monday, April 14, 2014 12:56:22 AM UTC-7, Ami Kapadia wrote: > > Hi! > > I am using CBL in my Phonegap application. I am creating native views > (Android and iOS). > *View v1 = db.getView(String.format("%s/%s",* > * strDbName,* > * "getrecords_typewise"));* > * v1.setMap(new Mapper() * > * {* > * @Override* > * public void map(Map<String, Object> document, Emitter emitter) * > * {* > * Object docType = document.get("type");* > * if (docType != null && * > * document.get("is_active") != null * > * && document.get("is_active").equals(true))* > * {* > * emitter.emit(docType.toString(), document);* > * }* > * }* > * }, strVersion);* > * db.registerView(v1);* > > Then I am querying views from JavaScript like this : > *config.views(["getrecords_typewise", {* > > * startkey : "contact",* > > * endkey : "contact",* > > * descending : true* > > * }], function(err, view)* > * {* > * var len = view['rows'].length;* > > *});* > > > I want to use live queries and on dbChange, I will update my associated UI > list. How can I do this? > -- You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/e8a3bf27-c58c-4f56-b777-d138f5f44faf%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
