title: How to update a user after a certain time in Node.js and Mongoose?
body: <p>How to automatically deduct credits from a user's available credits according to his active services renewal date?</p>
  
  <p>Let me describe what is the current scenario. Currently, I am working on an Express app which is basically a billing system which will automatically manage clients and charge them according to his active services. But I stuck! How to auto deduct credits from the user's account and renew the service or take the service on hold if he (the user) does not have sufficient balance.</p>
  
  <p>Here is what I have.</p>
  
  <p><strong>Services Schema:</strong></p>
  
  <pre><code>var mongoose= require('mongoose');
  var Schema = new mongoose.Schema({
    user:{
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      required: true
    },
    services:{
      username: {type: String, required: true, unique: true},
      package:  {type: String, required: true},
      domain:   {type: String, required: true, unique: true},
      status: String,
      dateAdded: {type: Date, default: Date.now },
      lastRenewed: Date,
      nextRenewal: Date,
      renewalCost: Number // Renewal Cost Of The Service.
    }
  })
  
  module.exports  = mongoose.model('Service', Schema);
  </code></pre>
  
  <p><strong>User Schema:</strong></p>
  
  <pre><code>var mongoose= require('mongoose');
  
  var Schema = new mongoose.Schema({
    name:{
      type: String,
      min: 1,
      required: true
    },
    username:{
          type: String,
          unique: true
    },
    password:{
      type: String, // Storing Hashed Password
      required: true
    },
    salt:{
      type: String
    },
    meta: {
      email: String,
      phone: Number,
      dateOfBarth: String,
      address: {
        companyName: String,
        address1: String,
        address2: String,
        city: String,
        state: String
     }
   },
  
   credit:{type: Number, default: 0},  // Avilable Credits
   isAdmin: {type: Boolean, default: false} // If The User Is Admin Or Not?
  
  
  });
  
  module.exports  = mongoose.model('User', Schema);
  </code></pre>
  
  <p>Now I want to run a query or a function (or something like it) on the "nextRenewal" date and deduct the renewal cost from the user's available Credits and save the user and also extend the next renewal date.</p>
  
  <blockquote>
    <p>Answer: Use  npmjs.com/package/node-schedule To schedule the job.</p>
    
    <p>Thanks to @Kilizo</p>
  </blockquote>