var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');

// Connection URL
var url = 'mongodb://localhost:27017/myproject';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  console.log("Connected correctly to server");
  insertFood(db, 5, "apple", 14, function(){
      insertFood(db, 3, "orange", 7, function(){
          db.close();
      });
  });
});

var insertFood = function(db, num, name, days, callback){
    var collection = db.collection('inventory');

    // insert the food and its attributes
    collection.insert(
        {
            "quantity": num,
            "type": name,
            "exp": days
        }, function(err, result){
            assert.equal(err, null);
            console.log("Inserted food into the inventory.");
            callback(result);
        });
};

@@ -418,17 +418,86 @@
     
-db.close(
+subtractFood(db, 2, %22apple%22, function()%7B%0A              db.close();%0A          %7D
 );%0A 
@@ -941,16 +941,16 @@
 esult);%0A
-
         
@@ -950,14 +950,524 @@
        %7D
+%0A    );%0A%7D;%0A%0Avar subtractFood = function(db, prevNum, saidNum, name, callback)%7B%0A    var collection = db.collection('inventory');%0A%0A    //remove the food%0A    collection.update(%0A        %7B%22type%22: name%7D,%0A        %7B%0A            $set: %7B%0A                %22quantity%22: prevNum - saidNum%0A            %7D%0A        %7D, function(err, result)%7B%0A            assert.equal(err, null);%0A            assert.equal(1, result.result.n);%0A            console.log(%22Quantity changed in inventory.%22);%0A            //callback(result);%0A        %7D%0A    
 );%0A%7D;%0A

subtract edit 1