I am trying to setup filtered replication between a master and user database. Documents in the master contain a list of user groups that have permission to the document.
{
_id: 'one',
groups: ['a', 'b']
}
{
_id: 'two',
groups: ['c', 'd']
}
I created a filtered view of the database that only allows user with the group to get a copy of the replicated document (hard coding the group of 'a' in this example)
{
filters = {
users = function(doc, req){
return doc.groups.indexOf(req.query.group) != -1;
}
}
}
I then create a replication document in the _replicator database
{
source: "master",
target: "user1",
filter: "replication/user",
query_params: {group: "a"},
create_target: true
}
Once this document is created replication begins and the document 'one' is replicated from master to user1. Document 'two' is not replicated - just what I want.
Subsequently the user is moved from group 'a' to group 'c' so I create a new replication document:
{
source: "master",
target: "user1",
filter: "replication/user",
query_params: {group: "c"},
create_target: true
}
The behaviour I want is for document 'one' to be removed from the user database and for document 'two' to be replicated. As it happens document 'one' remains and document 'two' is replicated. Obviously the replication filter does not allow for deletions in the target database unless the document is deleted in the source database.
How then should this scenario be handled? Or is there an alternate structure I should be considering?