Skip to content

twilson63/couchdb-expired

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CouchDb Expired Worker

This worker can be launched by cron or other scheduler to run daily and bulk deletions all expired documents from your couchdb databases.

Install

npm install expired -g

Getting started

First you want to create a config file, this file will list the server and all of your databases that you wish to manage: (eg. expired-config.json)

Config File Example

{
  "server": "http://localhost:5984",
  "dbs": ["*"],
  "_design_doc": {
    "_id": "expired",
    "language": "javascript",
    "views": {
      "_default": {
        "map": "function(doc) { \n  var expire = (new Date(doc.expires_in)),\n    today = (new Date());\n  if (expire < today) {\n    emit(doc._id, doc._rev);\n  }\n}\n"
      }
    }
  }
}

add command to crontab to run daily

crontab -e
0 3 * * * expired ~/expired-config.json

Now every day on the 3rd hour the expire job should run.

Tests

npm test

Development Environment

  • fork and clone
  • npm install
  • npm test

LICENSE

MIT

Contributions

  • Pull Requests welcome, please include tests

TODO

  • add test for design doc creation
  • add test for multiple databases

About

a simple worker app that marks expired documents as deleted.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published