简体   繁体   English

PouchDB 同步到错误的 CouchDB

[英]PouchDB syncs to wrong CouchDB

I am using electronjs and pouchdb to sync data to a remote couchdb.我正在使用 electronjs 和 pouchdb 将数据同步到远程 couchdb。 I have a remote dev couchdb that I use for testing purposes and a remote production couchdb.我有一个用于测试目的的远程开发沙发数据库和一个远程生产沙发数据库。

when I run electron.当我运行electron. the application syncs the data from the remote db and stores documents locally electron's pouchdb and vice versa.应用程序从远程数据库同步数据并将文档存储在本地电子的 pouchdb 中,反之亦然。

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.一切都很好,但是当我将远程数据库 URL 从 dev 更改为 prod 时,本地存储的 dev 数据会同步到生产 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.您不能只将远程数据库的 URL 从 Dev 更改为 Production。

Pouchdb does not know that this are two different databases and therefor starts syncing. Pouchdb 不知道这是两个不同的数据库,因此开始同步。 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.一个与 Dev 同步,另一个与 Production 同步。

The strength of CouchDB is that it can sync with any other Couch. CouchDB 的优势在于它可以与任何其他 Couch 同步。

If you are required to have two-way replication aka sync then you might consider filtered replication [1] .如果您需要进行双向复制,也就是sync ,那么您可以考虑过滤复制[1]

However if you only need to replicate remote documents to the local database, then simply use one-way replication [2] , for example但是,如果您只需要将远程文档复制到本地数据库,那么只需使用单向复制[2] ,例如

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


1 PouchDB Filtered Replication 1 PouchDB 过滤复制
2 PouchDB Replication 2 PouchDB 复制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM