From d6aa6c0c52c6696b13b9ded9056bdae75a39ab5c Mon Sep 17 00:00:00 2001 From: andreagerino Date: Fri, 27 Nov 2015 21:23:22 +0100 Subject: [PATCH] ... --- routes/storage.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/routes/storage.js b/routes/storage.js index 9921941..a5b5a18 100644 --- a/routes/storage.js +++ b/routes/storage.js @@ -11,12 +11,13 @@ var assert = assert = require('assert'); var mongoUrl = 'mongodb://icarus:icarus@localhost:27017/icarus'; //Use connect method to test the connection to the Server +var mongoDb; mongoClient.connect(mongoUrl, function(err, db) { assert.equal(null, err, err); debug("Connected to MongoDB database: "+db.databaseName); - db.close(); + mongoDb = db; }); @@ -29,8 +30,6 @@ router.get('/:resource_id', function(req, res, next) { debug(err); next(err); - db.close(); - }else{ var collection = db.collection('resources'); @@ -57,8 +56,6 @@ router.get('/:resource_id', function(req, res, next) { } - db.close(); - }); } @@ -76,8 +73,6 @@ router.post('/', function(req, res, next){ debug(err); next(err); - db.close(); - }else{ var collection = db.collection('resources'); @@ -94,7 +89,6 @@ router.post('/', function(req, res, next){ } else { - db.close(); res.statusCode = 201; res.send({"_id":r.insertedId}); @@ -110,8 +104,6 @@ router.post('/', function(req, res, next){ debug(error); next(error); - db.close(); - } } -- 2.18.1