I am new to node js and Mongo Db. I am trying to edit the user details . So for that I displayed the user list with Edit link for each user. When I click on edit link I passed the name of the user to the router and I am successfully able to get it there. But failed to find the details of user based on that passed name. Below is my code
router.get('/edit/:name', function(req, res){
var username= req.params['name'];
console.log(username);
db.collection('users').find({ name:username }).toArray(function (err, result) {
console.log(result);
if (err)
throw err;
res.render("edit-form", {details: result})
});
});
Here , when I do console.log(username); I got the username , but console.log(result); is empty. If I try to give the username directly within find method, just like below, I got the result in my page.
db.collection('users').find({ name:"test"}).toArray(function (err, result) {
console.log(result);
if (err)
throw err;
res.render("edit-form", {details: result})
});
How can I dynamically get the username so that I can get the corresponding user result from database.