{"id":18523591,"url":"https://github.com/mongoosejs/mongoose-ttl","last_synced_at":"2025-04-09T11:31:40.465Z","repository":{"id":2303359,"uuid":"3262248","full_name":"mongoosejs/mongoose-ttl","owner":"mongoosejs","description":"Provides time-to-live support for Mongoose","archived":false,"fork":false,"pushed_at":"2020-03-27T11:24:19.000Z","size":30,"stargazers_count":54,"open_issues_count":4,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T05:13:37.105Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://aheckmann.github.com/mongoose-ttl","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongoosejs.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-01-25T03:43:04.000Z","updated_at":"2023-03-23T12:20:41.000Z","dependencies_parsed_at":"2022-09-07T09:11:14.641Z","dependency_job_id":null,"html_url":"https://github.com/mongoosejs/mongoose-ttl","commit_stats":null,"previous_names":["aheckmann/mongoose-ttl"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoosejs%2Fmongoose-ttl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoosejs%2Fmongoose-ttl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoosejs%2Fmongoose-ttl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoosejs%2Fmongoose-ttl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongoosejs","download_url":"https://codeload.github.com/mongoosejs/mongoose-ttl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248031507,"owners_count":21036417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T17:36:23.767Z","updated_at":"2025-04-09T11:31:39.373Z","avatar_url":"https://github.com/mongoosejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongoose-TTL Plugin\n\nProvides time-to-live support for [Mongoose](http://mongoosejs.com).\n\n[![Build Status](https://secure.travis-ci.org/aheckmann/mongoose-ttl.png)](http://travis-ci.org/aheckmann/mongoose-ttl)\n\nOptions:\n\n  - ttl: the time each doc should live in the db (default 60 seconds)\n  - interval: how often the expired doc reaper runs (default 5 mins)\n  - reap: enable the expired doc reaper (default true)\n  - onReap: callback passed to reaper execution\n\nExample:\n\n```js\nvar ttl = require('mongoose-ttl');\nvar schema = new Schema({..});\nschema.plugin(ttl, { ttl: 5000 });\n```\n\nThe ttl option supports the ms module by [guille](https://github.com/guille) meaning\nwe can specify ttls with friendlier syntax. Example:\n\n```\n value     milliseconds\n========================\n '2d'      172800000\n '1.5h'    5400000\n '1h'      3600000\n '1m'      60000\n '5s'      5000\n '500ms'   500\n 100       100\n```\n\nThe expired document reaper can be disabled by passing `reap: false`.\nUseful when working in multi-core environments when we only want one\nprocess executing it.\n\n```js\nvar ttl = require('mongoose-ttl');\nvar schema = new Schema({..});\nschema.plugin(ttl, { ttl: 5000, reap: false });\nvar Cache = db.model('Cache', schema);\nif (isMyWorker) Cache.startTTLReaper();\n```\n\nThe reaper can also be stopped.\n\n```js\nCache.stopTTLReaper();\n```\n\nTime-to-live is specified at the collection level, however\nit can also be overridden for a given document.\n\n```js\nvar cache = new Cache;\ncache.ttl = '2m' // lives for two minutes\ncache.save();\n```\n\nWe can also reset the ttl for a given document to its\ndefault plugin state.\n\n```js\ncache.resetTTL();\n```\n## Mongoose Version\n\u003e= 2.5.2\n\n### MongoDB TTL collections\nMongoDB \u003e= 2.2 has official support for [TTL collections](http://docs.mongodb.org/manual/tutorial/expire-data/). The official feature is not quite as flexible as this plugin but offers alternative benefits a plugin cannot. Consider reading the [docs](http://docs.mongodb.org/manual/tutorial/expire-data/) and making an informed choice.\n\n[LICENSE](https://github.com/aheckmann/mongoose-ttl/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongoosejs%2Fmongoose-ttl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongoosejs%2Fmongoose-ttl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongoosejs%2Fmongoose-ttl/lists"}