I have an angular application using local storage (PouchDB) which automatically sync with a CouchDB database on a remote server.
As I would like to limit my application size, I would like to be able to archive automatically from CouchDB based on a condition.
Here is what I've imagined:
You could say that I can do this within my app but the problem is when the app is used offline, it cannot directly access the remote CouchDB to copy into another database.
So my question is, can CouchDB automatically copy a doc into another database (within same CouchDB) based on a value in the doc (archived = true for example)? If not, what would you suggest?
To preserve the last non-deleted version of each document, you could set up a continuous replication between your "data" and "backup" couchdb databases with a filter function that prevents _deleted docs from replicating, e.g:
function(doc, req){
return !doc._deleted
}
To exclusively preserve docs with an archive attribute set, you need to adjust your filter function:
function(doc, req){
return !doc._deleted && doc.archive
}
However, archiving a document now consists of two steps:
archive attribute set to your localDB, triggering its replication to your "data" database (and thus triggering its replication to the "backup" database)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With