4

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?

oliverdm
  • 381
  • 3
  • 10

1 Answers1

4

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. :)

nlawson
  • 11,510
  • 4
  • 40
  • 50
  • Thanks! Should have checked issues first... For some reason I wasn't using changes on the local database, so that already helps a lot. – oliverdm Mar 21 '15 at 12:18
  • Hi @nlawson, any update on this? I saw that the issue you mention was closed, and a new one is referenced: https://github.com/pouchdb/pouchdb/issues/1852 Should this issue fix the problem with several Pouchdb instances on different tabs? – nsacerdote Sep 01 '15 at 13:39
  • 1
    I believe the current status is that https://github.com/pouchdb/pouchdb/issues/1852 is still unresolved, meaning that replication in multiple tabs will work, but it'll just be inefficient. – nlawson Sep 01 '15 at 15:11