[英]How to work with databases in pouchdb
I'm making a list of tasks to learn how to use PouchDB / CouchDB, the application is quite simple, would have authentication and the user would create their tasks. 我正在制作一个任务列表,以学习如何使用PouchDB / CouchDB,应用程序非常简单,将具有身份验证,用户将创建他们的任务。
My question is regarding how to store each user's information in the database. 我的问题是如何将每个用户的信息存储在数据库中。 Should I create a database for each user with their tasks?
我应该为每个用户创建一个包含任务的数据库吗? Or is there a way to put all of the tasks of all users into a database called "Tasks" and somehow filter the synchronization so that PouchDB does not synchronize the whole database (including other users' tasks) that is in the server?
或者有没有办法将所有用户的所有任务放入名为“任务”的数据库中,并以某种方式过滤同步,以便PouchDB不同步服务器中的整个数据库(包括其他用户的任务)?
(I have read the pouchdb documentation a few times and I have not been able to define this, if it is documented, please inform me where.) (我已经阅读了几次pouchdb文档而且我无法定义这个,如果有文档,请告诉我在哪里。)
You can use both approaches to fulfill your use case: 您可以使用这两种方法来完成您的用例:
Database per user 每个用户数据库
Single database for every user 每个用户的单个数据库
Conclusion 结论
Which is better? 哪个更好? depends on your use case... In any case you should consider the scalability issues in both cases:
取决于您的用例...在任何情况下,您都应该考虑两种情况下的可伸缩性问题:
Both pattern are valid. 两种模式都有效。 The only difference is that in order to use the filtered replication, you need to provide access to the main database.
唯一的区别是,为了使用过滤的复制,您需要提供对主数据库的访问。
Since it's in javascript, it's easy to get credentials and then access the main database. 因为它是在javascript中,所以很容易获得凭据然后访问主数据库。 This would give users the ability to see everyone's data.
这将使用户能够查看每个人的数据。
A more secure approach would be to use a database-per-user pattern. 更安全的方法是使用每用户数据库模式。 Each database will be protected by the user's credentials.
每个数据库都将受到用户凭据的保护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.