Commit e67c00c4 authored by andreagerino's avatar andreagerino

...

parent d6aa6c0c
...@@ -11,28 +11,19 @@ var assert = assert = require('assert'); ...@@ -11,28 +11,19 @@ var assert = assert = require('assert');
var mongoUrl = 'mongodb://icarus:icarus@localhost:27017/icarus'; var mongoUrl = 'mongodb://icarus:icarus@localhost:27017/icarus';
//Use connect method to test the connection to the Server //Use connect method to test the connection to the Server
var mongoDb; var icarusDb;
mongoClient.connect(mongoUrl, function(err, db) { mongoClient.connect(mongoUrl, function(err, db) {
assert.equal(null, err, err); assert.equal(null, err, err);
debug("Connected to MongoDB database: "+db.databaseName); debug("Connected to MongoDB database: "+db.databaseName);
mongoDb = db; icarusDb = db;
}); });
router.get('/:resource_id', function(req, res, next) { router.get('/:resource_id', function(req, res, next) {
mongoClient.connect(mongoUrl, function(err, db) { var collection = icarusDb.collection('resources');
if(err!=null){
debug(err);
next(err);
}else{
var collection = db.collection('resources');
var _id = new ObjectID(req.params.resource_id); var _id = new ObjectID(req.params.resource_id);
collection.find({"_id":_id}).limit(1).next(function(err, doc){ collection.find({"_id":_id}).limit(1).next(function(err, doc){
...@@ -58,24 +49,11 @@ router.get('/:resource_id', function(req, res, next) { ...@@ -58,24 +49,11 @@ router.get('/:resource_id', function(req, res, next) {
}); });
}
});
}); });
router.post('/', function(req, res, next){ router.post('/', function(req, res, next){
mongoClient.connect(mongoUrl, function(err, db) { var collection = icarusDb.collection('resources');
if(err!=null){
debug(err);
next(err);
}else{
var collection = db.collection('resources');
var resource = req.body; var resource = req.body;
if(Object.keys(resource).length>0) { if(Object.keys(resource).length>0) {
...@@ -106,10 +84,6 @@ router.post('/', function(req, res, next){ ...@@ -106,10 +84,6 @@ router.post('/', function(req, res, next){
} }
} }
});
});
module.exports = router; module.exports = router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment