简体   繁体   中英

PouchDB syncs to wrong CouchDB

I am using electronjs and pouchdb to sync data to a remote couchdb. I have a remote dev couchdb that I use for testing purposes and a remote production couchdb.

when I run electron. the application syncs the data from the remote db and stores documents locally electron's pouchdb and vice versa.

Things are fine but when I change the remote database URL from dev to prod, the locally stored dev data gets synced to the production couchdb.

Is there any way (programmatically) to stop this from happening?

You can not just change the URL of the remote database from Dev to Production.

Pouchdb does not know that this are two different databases and therefor starts syncing. If you want a Dev and a Production Database you need to create two local databases. One that is synced with Dev and a separate one that is synced with Production.

The strength of CouchDB is that it can sync with any other Couch.

If you are required to have two-way replication aka sync then you might consider filtered replication [1] .

However if you only need to replicate remote documents to the local database, then simply use one-way replication [2] , for example

PouchDB.replicate('http://<remote host>/mydb', 'mydb');


1 PouchDB Filtered Replication
2 PouchDB Replication

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