简体   繁体   中英

How to sync CouchDB from multiple PouchDB in Angularjs?

I am working on an angular app. How I can make multiple PouchDB sync to a single CouchDB without any information loss?

if you mean by creating multiple PouchDB instances, then you have to create their respective listener to each PouchDB instance pointing to the remote DB you want ( the CouchDB in question ).

this example for the listener worked for me:

 var sync = PouchDB.sync('mydb', 'http://localhost:5984/mydb', { live: true, retry: true }).on('change', function (info) { // handle change }).on('paused', function (err) { // replication paused (eg replication up to date, user went offline) }).on('active', function () { // replicate resumed (eg new changes replicating, user went back online) }).on('denied', function (err) { // a document failed to replicate (eg due to permissions) }).on('complete', function (info) { // handle complete }).on('error', function (err) { // handle error });

You need to do replication by filter

  1. Created filter in CouchDB for every client databases;
  2. Start replication from CouchDB to client by filter (look at replication option named filter )
  3. Start replication for all documents from client to CouchDB for every client database.

You can find everything you need here (examples 3, 4)

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