简体   繁体   中英

PouchDB/CouchDB Sequence Counter on Replicate

I am live syncing a freshly minted pouchdb (3.3.1) to an established (iris) couchdb.

The initial replication happens successfully ( pause event fired).

If I do info() on the Local, I get an update_seq of 362 . If I do info() on the remote, it shows an update_seq of 4201 .

I think this makes sense to me: the local db has no revisions - only the leaves (ie there are 362 leaves in the db) whereas the remote db sequence counter reflects all the historical changes that have been made since it was first created.

My question is: how can I programatically determine what the initial 'offset' in sequence counter is between the two databases? In particular I want to be able to measure the progress of the initial replication.

You can't really compare the seqs across two databases. However, you can do a db.info() on the remote database, grab the update_seq , and then compare that to the last_seq that is given to you in the on('change') event during replication. This will tell you how much progress you've made.

If you would like to see an example of this, the NPM Browser does exactly this, to show the percent counter at the top. (It uses pouchdb-load as well, but the principle is the same, since the seqs are reported there as well.) The code is open-source, so feel free to check out how it works. :)

Edit: as pointed out in a comment, if you are using sync rather than replicate , you need to check the direction parameter when reading last_seq . Also for Cloudant, you will need to split the string on - to get the integer seq.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM