具有动态用户组的CouchDB复制策略

编程入门 行业动态 更新时间:2024-10-09 06:30:03
本文介绍了具有动态用户组的CouchDB复制策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这种情况: 我们有一系列共享某些文档的用户。他们可以共享的文档可能全天都会更改,文档本身(更改和删除)也可能会更改。用户可以更改文档上的某些信息。 例如: 文档 A | X A | Y A | Z B | X B | Z C | Y

可能的组:A + C,A + B

CouchDB上的服务器是a的副本使用此数据的SQL Server DB,ETL负责管理CouchDB上的更改。但是,CouchDB数据库是通过PouchDB在每个用户电话上复制的。

目标: 相应地复制更改和删除。

我们尝试过的操作: 1)我们认为我们将使用可以访问它的用户列表来构建文档。每个文档将具有一个用户数组,然后设计文档中的过滤器将负责复制到客户端。不幸的是,_changes提要中不存在无法通过过滤器的文档删除和文档更改(例如,从阵列中删除了用户),因此无法按每个用户在客户端 2)数据库上进行相应的复制。 。这是不可能的,因为用户需要看到每个用户组的其他人在文档上的工作(他们共享它们)。 3)。与第一个解决方案几乎相同的问题,但是更糟。实际上: -用户组可以更改并且不再存在:如何反映该客户端? -文档可以移至新的组:它将具有从头开始重新下载。这大大增加了下载大小 -同一文档可以在多个组中! (请参见上面的示例) -每个客户端每次登录并复制多个数据库时都必须知道她所在的组。然后,在回程中,您必须知道文档存在于哪个数据库上

有这种情况的解决方法吗?我是否缺少明显的解决方案?

EDIT

案例1的部分解决方案:

localDB.sync(remoteDB,{ live:true, retry:true, filter:'app / by_user', query_params:{ agente:agent} }) .on('paused',function(info){ console.log( paused) ; localDB.allDocs()。then(function(docs){ console.log( allDocs); docs.rows.forEach(function(row){ console.log(row); remoteDB.get(row.id) .then(function(doc){ if(doc.Agents.indexOf(agent)< 0){ localDB.remove(doc); } }); }); }); }) .on('change',function(result){ console.log( change!)); result.change.docs.forEa ch(function(change){ if(!change.deleted){ $ rootScope。$ apply(function(){ $ rootScope。$ broadcast('upsert',change);; }); } }); });

每个remove()给我409(冲突),是这样。有没有办法告诉Pouch不再将其视为可复制的,而只是将其从数据库中删除?

解决方案

(3 )对我来说似乎是最简单的解决方案,即每个角色的数据库解决方案。

我认为您的困难源于试图管理文档内部的权限(然后是使用过滤复制)。当您这样做时,您基本上是在尝试在文档中镜像CouchDB的权限系统,这会引起麻烦。

为什么不为每个角色创建数据库并分配使用常规 _users 数据库的用户角色?如果角色更改,则用户将失去或获得对一组文档的访问权限。您需要具有服务器端点来处理角色转换,或者需要设置具有特殊特权的单独的管理数据库,用户可以在其中更改角色。

<然后在客户端,您可以将多个CouchDB数据库复制到单个PouchDB中(然后将结果自己整理在一起),也可以复制到单个PouchDB中(如果需要双向同步,可能是个坏主意)。显然,您需要第一步来确定用户可以访问哪些数据库,但这在我看来是一个很小的缺点。

然后,如果用户失去对a的访问权限文档中,它们只会在复制期间出现401错误(在实时复制期间会显示在'denied'事件中)。不需要ddocs或经过筛选的复制-简单得多!

This is the situation: We have a series of users who share some documents. The documents they can share might change throughout the day, so can the documents themselves (changes and deletions). The users can change some information on the documents. E.g. Users | Documents A | X A | Y A | Z B | X B | Z C | Y

Possible groups: A+C, A+B

The server on CouchDB is a replica of a SQL Server DB with this data, an ETL takes care of managing changes on CouchDB. However, the CouchDB database is replicated on each user phone via PouchDB.

The goal: To replicate changes and deletions accordingly.

What we've tried: 1) we figured we'd structure our documents with a list of users that can access to it. Each document would have a "Users" array and then a filter in the design document would take care of the replication to the clients. Unfortunately document deletions and document changes that won't pass the filter (e.g. a user is removed from the array) are not present in the _changes feed so cannot be replicated accordingly on the clients 2) database per user. This is not possible, because users need to see each others work on the documents (they share them) 3) database per group of users. Pretty much the same problem as the first solution, but worse. In fact: - groups of user can change and no longer be present: how do reflect that client-side? - a document can shift to a new group: it will have to be redownloaded from scratch. This greatly increases the download size - the same document can be in more than one group! (see example above) - each client would have to know in which group she is everytime she logs in and replicate multiple databases. Then on the return trip you'd have to know on which databases the document was present

Is there a recipe for this situation? Am I missing an obvious solution?

EDIT

Partial solution for case 1:

localDB.sync(remoteDB, { live: true, retry: true, filter: 'app/by_user', query_params: { "agente": agent } }) .on('paused', function(info){ console.log("paused"); localDB.allDocs().then(function(docs){ console.log("allDocs"); docs.rows.forEach(function(row){ console.log(row); remoteDB.get(row.id) .then(function(doc){ if(doc.Agents.indexOf(agent) < 0){ localDB.remove(doc); } }); }); }); }) .on('change', function(result){ console.log("change!"); result.change.docs.forEach(function(change) { if(!change.deleted){ $rootScope.$apply(function(){ $rootScope.$broadcast('upsert', change); }); } }); });

Each remove() is giving me a 409 (conflict), and rightfully so. Is there a way to tell Pouch "no longer consider this as replicable and just remove it from my DB?"

解决方案

(3) Seems like the simplest solution to me, i.e. the "database per role" solution.

I think your difficulty stems from trying to manage permissions inside the documents themselves (and then using filtering replication). When you do that, you are basically trying to mirror CouchDB's permission system inside your documents, which is going to cause headaches.

Why not create a database per role, and assign roles to users using the normal _users database? If roles change, then users will lose or gain access to a set of documents. You would need to have server endpoints to handle the role-shuffling, or you would need to set up separate "admin" databases with special privileges, where users can change the roles.

Then on the client side, you can either replicate from multiple CouchDB databases into a single PouchDB (and then collate the results together yourself), or into a single PouchDB (probably a bad idea if you need to sync bidirectionally). Obviously you would need an initial step where you determine which databases the user has access to, but that's a small downside in my opinion.

Then if the user loses access to a document, they will simply get normal 401 errors during replication (which will show up in the 'denied' event during live replication). No need for ddocs or filtered replication - much simpler!

更多推荐

具有动态用户组的CouchDB复制策略

本文发布于:2023-07-22 00:48:41,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户组   策略   动态   CouchDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!