i have a server couch database with data of all users. I would like to replicate data of a particular user from this to another database (couch/pouch) on the client. i can't use different databases for different users on the server because there are documents that could be accessed by multiple users
eg: main database has
{"_id": "user1", "docs": ["doc1", "doc2"]},
{"_id": "user2", "docs": ["doc2", "doc3"]},
{"_id": "doc1", "name": "cow"},
{"_id": "doc2", "name": "monkey"},
{"_id": "doc3", "name": "dog"}
database for user1 should have after replication
{"_id": "user1", "docs": ["doc1", "doc2"]},
{"_id": "doc1", "name": "cow"},
{"_id": "doc2", "name": "monkey"},
and database for user2 should have after replication
{"_id": "user2", "docs": ["doc2", "doc3"]},
{"_id": "doc2", "name": "monkey"},
{"_id": "doc3", "name": "dog"}
i can get the user docs this way:
function(doc, req){
if (doc._id != req.query.userid){
return false;
}
return true;
}
but i can't think of a way to get the documents for a particular user using sorted ids since doc2 is common to both users and the documents doc1, doc2 and doc3 don't have user information.