JoCuTo
JoCuTo

Reputation: 2483

Deleting _deleted documents on CouchDB by date

My CouchDb database is getting bigger and I would like to remove documents by date also I would like to remove _deleted documents by date I know how to replicate my DB removing documents by date but:
¿Is there a way to do the same with _deleted documents? I mean remove _deleted documents by date

Upvotes: 4

Views: 4125

Answers (2)

natevw
natevw

Reputation: 17942

There's not really a way to conditionally cause a deletion using filtered replication, nor can you replicate a complete removal of a document.

You have a variety of options:

  • you can avoid replicating updates on old documents by filtering on date, but if they have already been replicated they won't be deleted
  • you can make a view to return old documents, and use a script to delete them at the source database. The deletions will replicate to any target databases, but all database will retain at least a {_deleted:true} tombstone of the documents [that's how the deletion gets replicated in the first place]
  • you can find old documents and _purge them, but you'll have to do that on each replica

What is your main goal?

If you have hundreds of objects and you want to hide the old ones from the UI of all replicas, write a script to find and DELETE/_delete:true them from in a source/master replica and the changes will propagate.

If you have bazillions of e.g. log messages and you need to free up space by forgetting old ones, write a script to find and _purge and finally _compact, then run it on every replica. But for a case like that, it might be better to rotate databases instead, e.g. manually "shard" or bin into a different database each week, and every week simply drop the N+1 weeks old database on each replica.

Upvotes: 3

Alexis Côté
Alexis Côté

Reputation: 3690

If your database is getting bigger, this is probably due to the versionning of your documents. A simple way to free some space is to run database compaction (Documentation)

As for _deleted documents, you can only REALLY delete them by purging

Therefore, it's not recommended to purge _deleted documents. It should only be done to remove very important files such as credentials.

Upvotes: 2

Related Questions