Javier Castro
Javier Castro

Reputation: 317

Pouchdb. How to verify a doc is replicated

Im using poychdb basically to let a mobile user create sales orders offline, then later replicate them to central couchdb server, then process them there on a cron job basis.

As replication can sync some docs...then stop (lost Internet. ..) i need a way to block the mobile user from editing those already synced orders. But hd can still edit other non-yet-uploaded orders

There is some way to do that?

Upvotes: 1

Views: 1182

Answers (1)

nlawson
nlawson

Reputation: 11620

The replicate() function returns an event emitter which emits a 'change' event: http://pouchdb.com/api.html#replication.

So you can listen for 'change' events, which will tell you how many documents were written and the seq (update sequence #) of the last written document. Using the changes feed and the since parameter, you can figure out which documents were already written to the remote database.

E.g. if the last_seq is 50, then changes({since: 50}) will give you all documents that haven't been synced yet.

Upvotes: 3

Related Questions