My PouchDB sync code is not producing a complete event.
I do get change and active and paused events (in that order), and the databases do eventually sync (after a very long wait even though there is not much data).
I need the complete event so I know when the remote CouchDB data is available locally to be used.
My code looks like this:
init(localDBName, remoteDBName)
// Initialises the database - Called every time the App starts or the user logs in or registers
// If remoteDBName is false we don't want to sync data to the server
{
// Create a new database or open it if it already exists
this._DB = new PouchDB(localDBName);
this.remote = remoteDBName; // If remoteDBName is false we don't sync data to the server
console.log('Data: init(): PouchDB database opened for localDBName = ' + localDBName + ' : ' + this._DB + ', remoteDBName = ' + this.remote);
// Sync to remote DB if we have been asked to
if (this.remote)
{
// Insert the url for the CouchDB server into the remoteDBName returned by PouchDB
var realRemoteDB = this.remote.replace("localhost:5984", COUCHDB_SERVER_URL);
console.log('Data: init: remoteDB path being used is: ' + realRemoteDB);
let options = {
live: true,
retry: true,
continuous: true
};
return this._syncHandler = this._DB.sync(realRemoteDB, options)
.on('complete', (info) => {
console.log('***** DATA: init() Complete: Handling syncing complete');
console.dir(info);
})
.on('change', (info) => {
console.log('***** DATA: init() Change: Handling syncing change');
console.dir(info);
})
.on('paused', (info) => {
console.log('***** DATA: init() Paused: Handling syncing pause');
console.dir(info);
})
.on('active', (info) => {
console.log('***** DATA: init() Active: Handling syncing resumption');
console.dir(info);
})
.on('error', (err) => {
console.log('***** DATA: init() Error: Handling syncing error');
console.dir(err);
})
.on('denied', (err) => {
console.log('***** DATA: init() Denied: Handling syncing denied');
console.dir(err);
});
}
else {
this.syncHandler = null;
}
}
The last event I get is the paused event which fires just after change event shows the data has been pulled from the server.