Search code examples
pouchdb

Multiple Pouchdb doesn't sync with couchdb


I am using pouchdb in my electron app,I have more than 15 database in my app. my problem is when i sync one or two database to couchdb it works great,but more than 3 couchdb doesn't sync.

My code :

var sync = PouchDB.sync('mydb', 'http://localhost:5984/mydb', {
  live: true,
  retry: true
})

I am also tried without live but it increase program complexity,however I manually want to place the code while perform insert,delete, update operations.

Can pouchdb watch put,update,delete events? To perform manual sync instead live

How should I achieve?

How to properly sync multiple database?

Which one I choose live sync or manual sync?

Is pouchdb fit for multiple database sync?


Solution

  • don't use database with live sync instead use manual sync with callback

    problems:

    1. multiple pouchdb sync makes multiple http request eg:(20 pouchdb sync makes 20 http request) so it is bad idea
    2. pouchdb live sync is good and fit for one or two database if you make 10 or 20 live pouchdb sync it makes always active10 or 20 http request so it is bad idea and also blocks your frontend dom
    3. don't use manualsync with setinterval ,setinterval also bad idea however it calls sync before sync completion

    solutions

    1. we keep single http request
    2. we call each db after one by one completion
    3. we always live without dom block however setimeout give relax for your dom

    code

        function sync(){
          setTimeout(function() {
        var sync = PouchDB.sync('db1', 'http://localhost:5984/db1')
            .on('complete', (info) => {
            PouchDB.sync('db2', 'http://localhost:5984/db2')
            .on('complete', (info) => {
            sync()
        });
        });
       },1000)
    }