Wayne Wei
Wayne Wei

Reputation: 3267

PouchDB sync with CouchDB conflicts with every update when using crypto-pouch plugin

I am using pouchDB in an angular App to store local data, and also using crypto-pouch 3.1.3 plugin to encrypt local data in IndexedDB.

Here is my code :

PouchDB = require('pouchdb').default;
  Crypto = require ('crypto-pouch');
  Upsert = require ('pouchdb-upsert');

  pouch: any;
  remoteDB: any;

  constructor() {

    this.PouchDB.plugin(this.Crypto);
    this.PouchDB.plugin(this.Upsert);
    this.pouch = this.PouchDB('localDB', { auto_compaction: true })

    this.pouch.crypto('password')


    this.remoteDB = new this.PouchDB(`https://somesite.com/p/remotedb/`)

    this.pouch.sync(this.remoteDB).on('error', function (err) {

          console.log('couch sync error', err);
          
         });;

  }

The data in browser IndexedDB has been encrypted and the replication to remote CouchDB is also happening.

But every time i make an update to local data, after the update has been synced with remote db, there is a conflict in remote CouchDB. conflict happens in _rev field, it is very confusing

If i remove the crypto code

this.pouch.crypto('password')

everything back to normal, the update could be synced and no conflict. Except the local data is displayed in plaintext in IndexedDB.

I assume it could be a problem with crypto-pouch plugin, so i went to its github issues list, but no such issues posted.

Anyone know what is problem is, and how to solve it? Thanks~

Upvotes: 1

Views: 224

Answers (0)

Related Questions