Sunday, 18 August 2013

Why Not I Am Getting The Query From MongoDB using this Method In NodeJS

Why Not I Am Getting The Query From MongoDB using this Method In NodeJS

Let me explain my problem first. I am trying to get the ID from URL and
use it to find a record in the database(MongoDB). The following code I
have in NodeJS Express App.
app.post('/dashboard/profile/update/:id',function(req,res){
var to_update=req.params.id;
var firstName=req.body.fname;
obj_to_search={_id:to_update};
db.open(function(err, dbs) {
if(!err) {
dbs.collection('project',function(err, collection) {
//update
collection.findOne(obj_to_search,
function(err, result) {
if (err) {
throw err;
} else {
res.send(result);
}
dbs.close();
});
});
}
});
});
I am getting the record if I hard code the ID to 1. But I am not getting
the record by this way. However I have checked using "console.log" the ID
i am getting throw URL is also 1.

No comments:

Post a Comment