How to rollback to the previous revision?

Greetings,

Is it possible and, if yes: how to rollback to the previous revision of a document (like git revert or git reset)?

Android native API is preferable. (I use couchdb lite 1.1.0).

Thanks in advance!

I don’t think so. Old revisions are “tombstoned” and are only around until they’re cleaned up. They’re not actually accessible.

It is often possible, but it’s not guaranteed, because old revision bodies are removed during database compaction, which happens periodically.

To get the parent revision it’s basically doc.currentRevision.parent. Then you can get its properties (if they’re not compacted away) via the userProperties property. If you got the properties you can use them to update/replace the properties of the current revision.

@unhuman thank you for explaining.

@jens Thank you. I try this approach. However, it would be better for my application if I could totally remove (purge) a revision with decreasing database sequence number. Is it possible?

(May be I have wrong understanding of Couch architecture, please sorry).

Thanks in advance,
Alexei

Jen,

Could you give some more details about to put an existing revision to doc? We have lot of documents which we don’t want to go through sync process, we want to manually put docs to couchbase lite through file reading. If I get revision from couchbase server, can I put same revision to couchlite?

1 Like

Compacting the database will accomplish this (for all documents.)

@zheng.gong - I don’t really understand what you’re asking, and it doesn’t sound like the same topic as Alexei’s. Could you start a new thread and describe your needs in more detail?

I was not accurate in my second question.
I hope, this is the final version of the topic: may I rollback to the previous revision (if it still exists), simultaneously purging current revision?
(Thus I will have the previous “state” of a document).

Thanks.

No, you can’t. Among other things, it would interfere with replication (the reverted revision will have an old sequence number so the replicator won’t see it as new and won’t propagate the change.)

Is there a reason you need to do this? (Remember, Couchbase Lite is not a version-control system…)

@jens

Thank you. Now I understand revision concept better.

I meant to use the revisions for undo operation in a distributed environment editor. I should to find another solution, maybe maintaining separate database for edit sequences.

Did you find solutions for this?