What happens with live queries when their database closes?

32 views
Skip to first unread message

Jordan Wood

unread,
Jan 26, 2016, 1:44:25 PM1/26/16
to Couchbase Mobile
My app has a whole bunch of live queries which we keep to monitor our data.  I want to be able to close the database and open another, and be able to replace the live queries with ones which refer to my new database.  Do live queries update when their database is closed?  What about ones where the query contains no documents?

Thanks!

Jordan

Jens Alfke

unread,
Jan 26, 2016, 4:20:43 PM1/26/16
to mobile-c...@googlegroups.com

On Jan 26, 2016, at 10:44 AM, Jordan Wood <wood.p...@gmail.com> wrote:

My app has a whole bunch of live queries which we keep to monitor our data.  I want to be able to close the database and open another, and be able to replace the live queries with ones which refer to my new database.  Do live queries update when their database is closed?

No. Closing a Database invalidates all objects derived from that database (Documents, Revisions, Views, Queries, Attachments, Replications, etc.) and you should not call them anymore (or expect them to call you.)

Similarly, closing a Manager invalidates all its Databases.

—Jens

Jordan Wood

unread,
Jan 31, 2016, 8:19:54 AM1/31/16
to Couchbase Mobile

Okay.  I've made my class with the CBLDatabase object a singleton, and have added an NSNotification whenever the database is opened or reopened, so the other objects can reacquire their live queries.  It all seems to be working!

Jordan
Reply all
Reply to author
Forward
0 new messages