I have this code
var UserSchema = new Schema({ Username: {type: String, index: true}, Password: String, Email: String, Points: {type: Number, default: 0} });
[...]
var User = db.model('User'); function savePoints(name, points){ if(name != "unregistered user"){ User.find({Username: name}, function(err, users){ var oldPoints = users[0].Points; var newPoints = oldPoints + points; User.update({name: name}, { $inc: {Points: newPoints}}, function(err){ if(err){ console.log("some error happened when update"); } else{ console.log("update successfull! with name = " + name); User.find({Username: name}, function(err, users) { console.log("updated : " + users[0].Points); }); } }); }); } } savePoints("Masiar", 666);
I would like to update my user (finding him with his name) updating my points. I am sure that oldPoints and points contain but my user continues to remain at zero points. Console fingerprints "update successful."
What am I doing wrong? Sorry for the stupid question / question.
Masiar
source share