node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »



Mongoose plugin to polling models


var poll = require('mongoose-poll');

var schema = new mongoose.Schema({
  state: {
    type: String,
    enum: ['init', 'running']
  scope: String,
  at: Date,
schema.plugin(poll, {
  path: 'state',
  sort: {at: -1},
  interval: 100,
  query: function(){return {at: {'$lte': new Date}, scope: 'scope1'};}

var Model = mongoose.model('test_model', schema);

Model.poll('init', 'running', function(doc){
  /* do something*/
  console.log("### doc found: ", doc);

var doc = new Model( {
  state: 'init',
  scope: 'scope1',
  at: new Date( + 5000)