0.0.7 • Published 8 years ago

ol-mongoose-ttl v0.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Build Status

ol-mongoose-ttl is mongoose plugin to set time-to-live to new created document. The plugin listen to 'post:save' event of mongoose and it will invoke only in case that the document is newly created and not updated.

Installation

npm install ol-mongoose-ttl --save

Tests

npm test

The plugin requires the schemna to have 'createdAt' and 'updatedAt' properties or similer that will passed through options

Usage

var mongoose = require('mongoose');
var ttl = require('ol-mongoose-ttl');
var Schema = new mongoose.Schema({ /* ... */ });
var model = mongoose.model('Schema', Schema);
var ttlOptions = {
  ttl: 5 * 60000, // time in ms
  operation: function(doc){
    // callback that will be invoke after {{ttl}}
    // ttl logic goes actualy here.
    // the callback have {{doc}} as mongoose document, means that you save doc.save() or doc.remove()
  },
  /*  updatedAt and createdAt are optional properties.
  *   If your document have other properties with the same meaning pass them as String, my recommendation to use mongoose-timestamp.
  */
  updatedAt: undefined, 
  createdAt: undefined, 
  model: model
}
Schema.plugin(ttl,ttlOptions)

License

The MIT License (MIT)

Copyright (c) 2013 Mihai Tomescu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago