I'm using Express 3.4.7 and mongo. I register a new character into my mongo database and then I would like to have my page (route : /game) but I want to get the data of the mongodb (like the _id) of my character.
Here is my code :
exports.newGame = function(ip, db){
return function(req, res){
//req.body return all the field
if(req.body.name && req.body.class) {
db.connect(dbconnection, function(err, db){
if(err) throw err;
var collection = db.collection('test'),
insertObj = {
name : req.body.name,
class : req.body.class
};
collection.insert(insertObj, function(err, data){
if(err) throw err;
console.log(data);
res.render('player/index', data); //Here is my problem
});
});
} else {
res.render('home/new', {title : 'Donjon & Gradon - New', ip : ip});
}
}
};
I would like to have the /game page and passing data and db after the query to mongo is OK.
I don't know if I am clear.
Can you help me ?
Regards,
Arnaud