question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replicate to remote CouchDB

See original GitHub issue

Hi, I’ve been struggling since some days to replicate data to a remote couchDB after I’ve encrypted my local Pouch with crypto-pouch.

First I thought it was not working because I was using a filter, as mentioned in issue 37. I removed the filter and still couldn’t make it work.

After testing, I could finally achieve replication after applying the crypto function to my remote database as well, using the same password.

If that’s the way it works, could you please make it more clear in your documentation?

Then, I noticed that this way, the data in my remote Couch were been inserted encrypted after the replication.

Is there a way to keep encrypted data on the client, but sent it unencrypted to the remote DB?

Many thanks in advance.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
tarazhongcommented, Jun 21, 2018

Hi, we had the same issue when encrypting a local PouchDB that was sync with a remote url :

Original code

this.localdb = new PouchDB('database');
this.localdb.crypto('password');
var remoteURL = 'http://127.0.0.1:5984/database'
let options = { .... }
this.localdb.sync(remoteURL, options)

What we did to solve this issue was to create 2 DBs, one encrypted DB that replicates data from Couchdb into a local Pouchdb (pull changes). One not encrypted remote DB but with no data stored that will push changes.

Adapted code

this.localdb = new PouchDB('database');
this.localdb.crypto('password');
var remoteURL = 'http://127.0.0.1:5984/database';
let options = { .... }
this.localdb.replicate.from(remoteURL, options);
this.remoteDB = new PouchDB(remoteURL, options);

All get/query requests are done with the localdb and all put/post requests are done with remoteDB.

Also we had to modify crypto pouch index.js file, to add ‘_revisions’ to ignore variable (line 18 var ignore = [‘_id’, ‘_rev’, ‘_deleted’,‘_revisions’]) otherwise localDB will not handle pull changes.

3reactions
jackkleemancommented, Feb 6, 2017

I have a solution for this; have two pouchdb instances, one with crypto pouch loaded as a plugin, one without. Do all your document manipulation in your crypto instance, but setup replication in your blank instance. It’s a little hacky, but was a 2-3 line change for me that works out the box. Data is sent to the server encrypted, and you could then set up the couch server to be able to decrypt given the same password.

I am using this for a zero knowledge application where the server doesn’t have access to any user data, its just a dumb store.

Read more comments on GitHub >

github_iconTop Results From Across the Web

2.1. Introduction to Replication - CouchDB Docs
During replication, CouchDB will compare the source and the destination database to determine which documents differ between the source and the destination ...
Read more >
Replication - PouchDB
You have an in-memory PouchDB that replicates with a local PouchDB, acting as a cache. You have many remote CouchDB databases that the...
Read more >
16. Replication - CouchDB: The Definitive Guide [Book]
A remote database is identified by the same URL you use to talk to it. CouchDB replication works over HTTP using the same...
Read more >
Replicating CouchDB data from remote server to local computer
I've recently started playing with CouchDB and just into some small issues. I am trying to replicate data from a aremote server to...
Read more >
Replicating from a Query with CouchDB | by Glynn Bird
Apache CouchDB's replication protocol allows documents to be copied from a source database to a target database with the minimum of fuss.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found