oliverdm
oliverdm

Reputation: 381

How to handle multiple PouchDB instances in the browser that sync with the same db?

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

My setup is a web application in the browser that synchronizes continuously with a remote CouchDB. That web app could be opened more than once (multiple tabs/windows) and thus create multiple PouchDB instances that try to sync.

In such a case, only one PouchDB instance will report remote changes - other instances produce a conflict during live sync:

{
  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
}

Do I need to ensure that only one PouchDB instance syncs at a time and pass changes around manually?

Upvotes: 4

Views: 1914

Answers (1)

nlawson
nlawson

Reputation: 11620

PouchDB replication currently does not work in multiple tabs. It is an open issue, and anybody who wants to hop in would be more than welcome to. :)

Upvotes: 4

Related Questions