简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM