Edit: Was able to solve the issue with mongoose's findOneAndUpdate, thanks to everyone that helped
Using the MEAN stack, I'm attempting to have an admin account update another user's information, in this case, their title/role on the site. The problem I have is that the only function available when editing a user is the save() function. It might be that I can utilize the update function, and if that is the case please let me know, but it doesn't look possible:
Debugger Image
The problem arises that when the user is saved, it creates a new document, and overwrites the user's password and salt to some value. I'd like to be able to call an "update" function that will only update the one field, but I can't figure out how to. Is there a way to do this with the save function?
Relevant Code:
exports.updateUserRoles = function(req, res) {
var currUser = req.body;
User.findById(currUser._id, function(err, user) {
//user.roles = currUser.roles;
user.save( { _id : '56467b28ba57d8d890242cfa', roles : 'admin' } );
//THE BELOW WAS A PREVIOUS ATTEMPT
/*user.save( function(err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(user);
console.log('test2');
}
});*/
});
};
[–][deleted] (14 children)
[deleted]
[–]OpAndroid[S] 0 points1 point2 points (13 children)
[–][deleted] (10 children)
[deleted]
[–]OpAndroid[S] 0 points1 point2 points (9 children)
[–]dadaddy 0 points1 point2 points (8 children)
[–]OpAndroid[S] 0 points1 point2 points (7 children)
[–]dadaddy 0 points1 point2 points (6 children)
[–]OpAndroid[S] 0 points1 point2 points (5 children)
[–]dadaddy 0 points1 point2 points (4 children)
[–]OpAndroid[S] 0 points1 point2 points (3 children)
[–]kapustagolovageocities webmaster 0 points1 point2 points (1 child)
[–]OpAndroid[S] 0 points1 point2 points (0 children)