[Couchbase-lite] How to edit or replace an existing document if it has not been synced?

67 views
Skip to first unread message

Anish Singh

unread,
Jun 8, 2015, 1:37:57 AM6/8/15
to mobile-c...@googlegroups.com
From what I have understood, to update a document you have to always create a new document (revision).

Consider the following scenario:
Suppose if the user is creating a lot of edits in a short period of time. For example, if the user is continuously tapping on a list-item in a TODO app.
Given the fact that, we always create a copy of the document on every update, this would take a lot of space on Couchbase server. I did 500 taps on a list-item in GrocerySync app and the disk usage shot up by 6 MB in couchbase server. Yes, these documents (or revisions) eventually get cleaned up but even if it does, the revision-manager document for this document will just bloat up.

So, is it possible to edit or replace an existing document revision if it has not been synced with the sync-gateway?
(To handle this, I am planing to sync with sync-gateway in my app every 5 secs. So, for every 5 sec only one revision will be synced.)

Also, how can I control sync? I want to manually trigger a sync.

James Nocentini

unread,
Jun 8, 2015, 10:38:18 PM6/8/15
to mobile-c...@googlegroups.com
So, is it possible to edit or replace an existing document revision if it has not been synced with the sync-gateway?
(To handle this, I am planing to sync with sync-gateway in my app every 5 secs. So, for every 5 sec only one revision will be synced.)

If you set up the maxRevTreeDepth property on your database, Couchbase Lite will automatically delete revisions older that the specified tree depth.
 
Also, how can I control sync? I want to manually trigger a sync.

You can use the start/stop methods on the Replicator to trigger a sync.

James

Jens Alfke

unread,
Jun 8, 2015, 10:47:03 PM6/8/15
to mobile-c...@googlegroups.com
On Jun 7, 2015, at 10:34 PM, Anish Singh <anis...@gmail.com> wrote:

Given the fact that, we always create a copy of the document on every update, this would take a lot of space on Couchbase server.

Older revisions will be deleted to make room. Also, the replicator only transfers the latest revision of a document.

I did 500 taps on a list-item in GrocerySync app and the disk usage shot up by 6 MB in couchbase server. Yes, these documents (or revisions) eventually get cleaned up but even if it does, the revision-manager document for this document will just bloat up.

The revision history (the list of old revIDs) will get pruned after a while too, and as James said, you can set it to a smaller limit to.

So, is it possible to edit or replace an existing document revision if it has not been synced with the sync-gateway?

Replication has nothing to do with updating documents. You can update documents as much as you like whether or not there’s a replication running.

(To handle this, I am planing to sync with sync-gateway in my app every 5 secs. So, for every 5 sec only one revision will be synced.)

It’s a lot more efficient to have a continuous replication and leave it running.

—Jens

Reply all
Reply to author
Forward
0 new messages