var mongoDB = require("mongodb"),
	MongoClient = mongoDB.MongoClient,
	path = require("path"),
	express = require("express"),
	bodyParser = require('body-parser'),
	app = express();

app.use(bodyParser.urlencoded({
	extended: true
}));

MongoClient.connect('mongodb://' + process.env.IP + ':27017/kjmg', function(err, db) {

	if (!err) {

		app.use(express.static(__dirname + '/public'));

		app.post('/complex', function(req, res) {
			db.open(function(err, db) {
				if (!err) {
					db.collection('complexContact').insert(req.body);

					db.collection('complexContact').find().toArray(function(err, data) {
						if (!err) {
							res.send(data);
						}
					});
				}
			});
		//	db.close();




		});

		app.post('/delete', function(req, res) {
		
			db.open(function(err, db) {
				
				if (!err) {

					db.collection('complexContact').remove({_id: new mongoDB.ObjectID(req.body.id)}, function(err, data) {
						console.log("error" +err);
						console.log("Data" +data);
						db.collection('complexContact').find().toArray(function(err, data) {
							if (!err) {
								res.send(data);
							}
						});

					});

				}
			});
		




		});

		app.post('/update', function(req, res) {
			db.open(function(err, db) {
				if (!err) {
					db.collection('complexContact').insert(req.body);

					db.collection('complexContact').find().toArray(function(err, data) {
						if (!err) {
							res.send(data);
						}
					});
				}
			});
		
		});
		app.listen(process.env.PORT);

	}

});

@@ -677,16 +677,17 @@
 %09%09%7D);%0A%09%09
+%09
 //%09db.cl
@@ -693,16 +693,16 @@
 lose();%0A
-
 %0A%0A%0A%0A%09%09%7D)
@@ -747,19 +747,17 @@
  res) %7B%0A
-%09%09
 %0A
+
 %09%09%09db.op
@@ -783,13 +783,9 @@
 ) %7B%0A
-%09%09%09%09
 %0A
+
 %09%09%09%09
@@ -842,16 +842,23 @@
 remove(%7B
+%0A%09%09%09%09%09%09
 _id: new
@@ -887,16 +887,22 @@
 body.id)
+%0A%09%09%09%09%09
 %7D, funct
@@ -922,74 +922,8 @@
 ) %7B%0A
-%09%09%09%09%09%09console.log(%22error%22 +err);%0A%09%09%09%09%09%09console.log(%22Data%22 +data);%0A
 %09%09%09%09
@@ -1083,15 +1083,13 @@
 %7D);%0A
-%09%09%0A
 %0A%0A%0A%0A
+%0A
 %09%09%7D)
@@ -1218,35 +1218,166 @@
 ntact').
-insert(req.body);%0A%0A
+update(%7B%0A%09%09%09%09%09%09_id: new mongoDB.ObjectID(req.body.id)%0A%09%09%09%09%09%7D, %7B%0A%09%09%09%09%09%09name: req.body.name,%0A%09%09%09%09%09%09phone: req.body.phone%0A%09%09%09%09%09%7D, function(err, data) %7B%0A%09
 %09%09%09%09%09db.
@@ -1440,32 +1440,33 @@
 , data) %7B%0A%09%09%09%09%09%09
+%09
 if (!err) %7B%0A%09%09%09%09
@@ -1453,32 +1453,33 @@
 %09%09%09%09if (!err) %7B%0A
+%09
 %09%09%09%09%09%09%09res.send(
@@ -1483,34 +1483,45 @@
 nd(data);%0A%09%09%09%09%09%09
+%09
 %7D%0A
+%09%09%09%09%09%09%7D);%0A
 %09%09%09%09%09%7D);%0A%09%09%09%09%7D%0A%09
@@ -1505,32 +1505,34 @@
 %09%09%09%7D);%0A%09%09%09%09%09%7D);%0A
+%0A%0A
 %09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%0A
@@ -1528,18 +1528,16 @@
 %0A%09%09%09%7D);%0A
-%09%09
 %0A%09%09%7D);%0A%09

update functionality