title: Mongoose Middleware in separate scripts
body: <p>The project I'm working on involves one script connecting to a websocket and updating the database every 6 hours.</p>
  
  <p>I have another script that will use the information in that database, but needs to know when the table has been updated with new data (every 6 hours).</p>
  
  <p>db-script.js</p>
  
  <pre><code>mongoose.connect('mongodb://localhost/db-example', function (err) {
          Schema.updateOne({ _id: "some_id"}, {
              data: data
          }, { upsert: true }, (e, r) =&gt; {
              if (e) console.log(e);
              console.log(r);
          });
  });
  </code></pre>
  
  <p>main-script.js</p>
  
  <pre><code>    mongoose.connect('mongodb://localhost/db-example', function (err) {
          if (err) throw err;
          Schema.post('save', function (doc) {
              console.log('just updated', doc._id);
          });
      });//mongoose.connect 
  </code></pre>
  
  <p>Is this the correct way to handle such a case? Is there a better way to do so? I could go about simply setting a timeout to query the db every 6 hours, but that would require a reasonable delay which is not ideal.</p>