How to handle multiple instances of PouchDB in a browser that are synchronized with the same db?

What is the recommended way to work with multiple instances of PouchDB in a browser that synchronize simultaneously with the same remote / local database?

My setup is a web application in a browser that continuously syncs with a remote CouchDB. This web application could be opened several times (several tabs / windows) and, thus, created several instances of PouchDB that try to synchronize.

In this case, only one instance of PouchDB will report remote changes - other instances create a conflict during direct synchronization:

{
  error: true,
  message: "Document update conflict",
  name: "conflict",
  result: {
    doc_write_failures: 0,
    docs_read: 1,
    docs_written: 1,
    end_time: ...,
    errors: [
      CustomPouchError
    ],
    last_seq: 963,
    ok: false,
    start_time: ...,
    status: "aborting"
  },
  status: 409
}

Should I ensure that only one instance of PouchDB is synchronized at a time and passes the changes manually?

+4
1

PouchDB . , , , .:)

+3

All Articles