简体   繁体   English

将多个PouchDB数据库同步到一个CouchDB数据库

[英]Sync multiple PouchDB databases to one CouchDB database

In PouchDB Documentation I found that sync is between local database and the remote CouchDB database. 在PouchDB 文档中,我发现同步是在本地数据库和远程CouchDB数据库之间。 I'm trying to build a native application that have a local database for every user (many databases) and sync to one remote database: 我正在尝试构建一个本机应用程序,它为每个用户(许多数据库)提供本地数据库并同步到一个远程数据库:

Let's say that user 01 syncs to the remote database, then user 02 syncs to it too. 假设用户01同步到远程数据库,然后用户02也同步到它。 I think it'll override the data of the first user. 我认为它会覆盖第一个用户的数据。 This is what I want: 这就是我要的:

// Default
user1 = ['data']
user2 = ['data']
remote = [user1 or user2]

// what i want
user1 = ['data']
user2 = ['data']
remote = [user1, user2, ....etc]

Replication relies on the sequence of the databases being synced. 复制依赖于正在同步的数据库的序列。 Thus, you only "overwrite" data when their _id values will clobber one another. 因此,当它们的_id值相互冲突时,您只“覆盖”数据。 However, I suspect the next issue you'll need to contend with is keeping user data separate. 但是,我怀疑您需要应对的下一个问题是将用户数据分开。

If you replicate all your users into a single database, all your users will also receive every other users' data as well when they replicate back out of that single database. 如果将所有用户复制到一个数据库中,那么当所有用户从该单个数据库中复制回来时,所有用户也将收到所有其他用户的数据。 I'm not sure what your use-case is, but that isn't generally how apps are structured. 我不确定你的用例是什么,但通常不是应用程序的结构。 If you want to use a single database like this, you'll need to include some sort of tagging to your documents and use Filtered Replication . 如果要使用这样的单个数据库,则需要在文档中包含某种标记并使用Filtered Replication

To keep your data segmented by user, you'll need to be diligent in using this parameter every time you sync. 为了保持用户对数据进行分段,您需要在每次同步时都努力使用此参数。 However, your database is probably exposed to the public internet if you're syncing them, and the lack of document-level controls means your savy users will be able to see everyone else's data anyways. 但是,如果您正在同步它们,您的数据库可能会暴露给公共互联网,而缺乏文档级控制意味着您的精明用户无论如何都能够看到其他人的数据。

My recommendation here is to give each user their own database, rather than replicating everything into a single hub database. 我的建议是为每个用户提供他们自己的数据库,而不是将所有内容复制到一个中心数据库中。 With CouchDB 2.x, you have access to couch_peruser , which gives each registered user their own database automatically. 使用CouchDB 2.x,您可以访问couch_peruser ,它会自动为每个注册用户提供自己的数据库。 (this will require registering your users with CouchDB as well, but honestly it's the best for security in a publicly-exposed server anyways) (这也需要使用CouchDB注册您的用户,但老实说,无论如何,这对于公开的服务器来说是最好的安全性)

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

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