diff --git a/routes/storage.js b/routes/storage.js index 99219416a2eda1e360eb175be4ac370474ea497c..a5b5a18116b07b34d46c07f33da69c01be543b0e 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(); - } }