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

天涯浪子 提交于 2019-12-10 15:21:40

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/29173889/how-to-handle-multiple-pouchdb-instances-in-the-browser-that-sync-with-the-same

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!