jeff
jeff

Reputation: 3327

Cloudant filtered replication, removing documents from target

I've got one db per user, from which I use a filtered replicate to send documents marked public into a single common database. I have this working. now when a user changes their document from public to private, the replications does not clear the document from the common database.

Aside from reading all of the private documents from the userDb and then removing them from the common db (if they exist), is there anyway to accomplish this via fundamental replication features?

Upvotes: 0

Views: 223

Answers (1)

rhyshort
rhyshort

Reputation: 1453

Short answer: No.

Long answer: The replicator will not delete documents on the remote unless the document was deleted in the local database. Filter functions just determine what is allowed to be replicated. So your use case can be done but in a way I would think is slightly abusive of the CouchDB model if the user changes the document to private, you could:

  1. Cache the document content on the device the user made the change.
  2. Delete the document in the remote database
  3. Re create the document using the cached content with the fields updated to indicate it is private.

As long as your filter function allows deletes to be replicated to the remote, the document will be deleted, however the usual caveats around how CouchDB deletes documents apply.

Upvotes: 0

Related Questions