Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including mongoose-poll with all npm packages installed. Try it out:

var mongoosePoll = require("mongoose-poll")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

mongoose-poll v0.0.3

plugin to polling mongoose


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)


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free