0

I would like to update my mongodb using angularjs and nodejs. I would like to update using the id.

I found the following code which updates object with id 1. I would like to pass the id as a parameter and then update the object

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!');
  });

});
}

Can you help

0

1 Answer 1

1

you can pass the id on the request and then just access it

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
Sign up to request clarification or add additional context in comments.

2 Comments

tHANK YOU SO MUCH CAN YOU SHOW ME HOW TO CALL IT IN ANGULAR CONTROLLER
for that you should just open another question or something because i am not very used to angular and probably would give you a bad anwser :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.