PouchDB Continues Polling Offline

I am working on webapp using PouchDB as a local database and CouchDB as a central database. One of the reasons I use PouchDB is because I want to use offline support in my application. However, I ran into a little problem. When you go offline and reconnect to the network, PouchDB no longer syncs. I need to update browsers in order to start synchronization again. One solution would be that even if the application is offline, PouchDB will continue to poll the remote database, even if it is disconnected, which will cause synchronization to pick up again when reconnected. Another solution would be to let the user manually manually report this to the application and get synchronization from there.

How can I tell PouchDB to start syncing again? If I can do this, I can solve my problem.

+4
source share
4 answers

The goal of PouchDB is to mirror CouchDB with the parity of the function, one of the features of CouchDB replication is that it will time out after a while if it is disabled, so you will need to start replay, as you already noted.

There is an open problem ( https://github.com/pouchdb/pouchdb/issues/966 ) about infinite replication, so this will not be a problem, but until then you can use the same replication call that you used to start replication in first of all:

db.replicate.to(remoteDB, [options]);

http://pouchdb.com/api.html#replication

- - http://github.hubspot.com/offline/docs/welcome/, , , PouchDB.

+1

PouchDB 3.1.0 retry API .

https://github.com/pouchdb/pouchdb/commit/47d105edaa9e36006124636235be8016c2e8c52c

PouchDB.replicate.sync('http://remote', {
    live: true,
    retry: true
})
+2

, , :

var retryMs = 2000;
function replicateFrom() {
  var opts = {live: true};
  db.replicate.from(remoteCouch, opts).on('error', function() {
    console.log('replication error');
    setTimeout(replicateFrom, retryMs);
  });
}

db.replicate.to

+1

pouchdb-persist, .

var db = new PouchDB('todos');

// Instead of db.replicate()
var persist = db.persist({ url: 'http://localhost:5984/todos' });

connect disconnect.

+1

Source: https://habr.com/ru/post/1533053/


All Articles