Cannot recreate the database after deletion on IOS

40 views
Skip to first unread message

Constantine Kozak

unread,
Dec 20, 2015, 11:18:21 PM12/20/15
to Couchbase Mobile
I have a case when a user should to be able to log out of the application (local database should be deleted) and log in again using a different or the same account. When a user logs in I access the database using CBLManager.sharedManager() and set up replication.

So for the initial case everything works perfectly. When a user logs out, I call db.deleteDatabase() and close it. But then when a user logs back the database is not accessible unless the application is restarted. createQuery() method returns nils, attempts to insert something fails with 

Foundation._GenericObjCError.NilError: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.1.101.15/src/swift/stdlib/public/core/ErrorType.swift, line 50


I use Typhoon so the class that holds manager and database should be the same. I've tried to recreate the CBLDatabase object on re-login but it doesn't change anything.


What is a correct workflow to drop the database and then to recreate and reconnect to it?

Jens Alfke

unread,
Dec 21, 2015, 1:56:55 PM12/21/15
to mobile-c...@googlegroups.com

On Dec 20, 2015, at 8:18 PM, Constantine Kozak <mak...@gmail.com> wrote:

So for the initial case everything works perfectly. When a user logs out, I call db.deleteDatabase() and close it. But then when a user logs back the database is not accessible unless the application is restarted. createQuery() method returns nils, attempts to insert something fails with 

What’s the code you use to re-create the database? You should be able to just call CBLManager.databaseNamed(“foo”).

However, if you expect the logged-out user to log back in later, it would make more sense to keep their database around and avoid having to download the docs again. So don’t delete databases, just use a separate database for each user (for instance, with a name based on after their username, keeping in mind the limited character set available for database names.)

—Jens

Constantine Kozak

unread,
Dec 21, 2015, 6:27:00 PM12/21/15
to Couchbase Mobile
Thanks. It's an interesting optimization and worked fine for me.

Meanwhile I've found the source of my original problem - when I was deleting the database I wasn't resetting my replication variables. So when a database was closed, replication variable would still point to the old database. Silly mistake. 
Reply all
Reply to author
Forward
0 new messages