javaandroidcouchbase-lite

delete whole couchbase lite db issue


I wanna delete my entire Couchbase lite DB, but for some reasons some records won't be deleted, I tried the following code:

try{ db.delete()} catch{...}

but it won't work, it seems like SQLite got some problems with old indexes, with something like:

revisionId has already existed...

any help would be appreciated.


Solution

  • try this..

    first stop replication and then delete DB

    public void stopReplication() {
        if (mPull != null) {
            mPull.stop();
        }
        if (mPush != null) {
            mPush.stop();
        }
        Log.d(TAG, "stopReplication: success");
    }
    
    public boolean deleteAllDocuments() {
        try {
            mDatabase.close();
            mDatabase.delete();
            mDatabase = null;
            mManager = null;
            Log.d(TAG, "deleteAllDocuments: success");
            return true;
        } catch (CouchbaseLiteException e) {
            e.printStackTrace();
            Log.e(TAG, "deleteAllDocuments: Failed to close and delete database.");
    
        }
        catch (Exception e)
        {
            e.printStackTrace();
            Log.e(TAG, "deleteAllDocuments: Failed to close and delete database.");
        }
        return false;
    }
    

    happy coding... :)