Creating documents in empty cblite db with old revision id's (cordova plugin)

24 views
Skip to first unread message

Vinay Bhinde

unread,
Mar 17, 2015, 9:42:02 AM3/17/15
to mobile-c...@googlegroups.com
Hello,

I am using cblite phonegap plugin in hybrid app that works across iOS and Android.

There is backup feature in the application which allows user to take backup of data from any device/OS on my server and restore it on any other device/OS.

I am facing an issue in the following scenario :

- user takes backup with x number of docs created on Device A
- user now is on device B and performs restore of x docs each of which contain a revision id
- on device B what i do is get all the x docs from my server and issue a PUT request with rev id present in each docs
- this gives me 404 error as the db on device B is blank and hence it wont accept docs with revision id's because it won't be able to find older revisions which is correct.

But the issue is that i need to keep the rev id of docs intact across devices.

Also you might suggest i need to use sync but it as offered as another service which is different then Backup in my app.

Basically what SG does while syncing docs to different devices, i want to do the same manually (i.e put or post docs with a rev id where the doc did not exist before )

Any help ?

If there's any confusion i will be happy to explain more

Jens Alfke

unread,
Mar 17, 2015, 11:44:58 AM3/17/15
to mobile-c...@googlegroups.com

On Mar 17, 2015, at 6:42 AM, Vinay Bhinde <vin...@gmail.com> wrote:

- on device B what i do is get all the x docs from my server and issue a PUT request with rev id present in each docs
- this gives me 404 error as the db on device B is blank and hence it wont accept docs with revision id's because it won't be able to find older revisions which is correct.

Add “?new_edits=false” to the URL of the PUT. This tells CBL that you’re inserting an existing revision instead of creating a new one. (This is the same flag used by the replicator.)

Also, if you want the replicator to work properly with these documents (i.e. to not get confused if it later pulls the same document from a server) you should insert the complete revision history along with the document. To do that, when you GET the document from the remote server, add “?revs=true” to the URL. That will add a “_revisions” property to the document containing the list of ancestor revision IDs. When you PUT this document, CBL will detect the “_revisions” property and use it to recreate the doc’s revision history.

—Jens
Reply all
Reply to author
Forward
0 new messages