title: How do i update a field in mongodb?
body: <p>My goal is to update <code>timeleft</code> field on every object in the itemSchema.</p>
  
  <pre><code>const ItemSchema = mongoose.Schema({
      name: String,
      time: { type: Date, default: Date.now },
      timeleft: { type: Number, default: 24 }
  });
  </code></pre>
  
  <p>For example in order for me to update every object in the <code>ItemSchema</code></p>
  
  <pre><code>ItemSchema.methods.calculateTime = function() { // Done check it one hour
  
    var currentTime = moment() // Get current Time
    var timeStored = moment.utc(this.time).local().format(); // Convert this.time UTC to local time
    var timeDiff = currentTime.diff(timeStored, 'h'); // See the difference in time example - 7
    this.timeleft -= timeDiff; // Deduct timeleft witht he timeDiff , result would be 17
    this.save(); // Simple save it to the database
  }
  </code></pre>
  
  <p>API example</p>
  
  <pre><code>app.get('/allItems', function(req, res) {
      Item.find({}, function(err, items) {
        // I want to run items.calculateTime(); but it is not possible.
        // How would I run calculateTime function on the array of objects?
      });
  });
  </code></pre>
  
  <p>My goal is to keep checking the time difference and save it to the time left</p>
  
  <p>Data example</p>
  
  <pre><code>timeleft: 24
  
  // after calculateTime
  time: 17 
  
  Because I want to show this to the User
  
  // 17 hours left
  </code></pre>
  
  <p>How would I do this to array of objects, instead of single object?</p>