2016-11-29 67 views
0

我想用angularjs和nodejs更新我的mongodb。我想用id来更新。使用nodejs和angularjs更新mongodb

我发现下面的代码更新ID为1的对象,我想通过ID作为参数,然后更新

module.exports.updateUser = function (req, res) { 
// get a user with ID of 1 
User.findById(1, function(err, user) { 
    if (err) throw err; 

    // change the users location 
    user.auto = 'true'; 

    // save the user 
    user.save(function(err) { 
    if (err) throw err; 

    console.log('User successfully updated!'); 
    }); 

}); 
} 

你能帮

回答

1

你可以通过ID的对象该请求,然后就访问它

module.exports.updateUser = function (req, res) { 
var id = req.body.id; 
// get a user with ID of id 
User.findById(id, function(err, user) { 
    if (err) throw err; 
//update the object like you want 
//save the object like you were doing 
+0

谢谢你这么多你能告诉我怎么称呼它 - 在角度控制器 –

+0

为你应该打开另一个问题或someth因为我不是很习惯角度,可能会给你一个不好的anwser:D – rule

+0

好吧谢谢反正 –