title: What am I doing wrong on my update function on nodejs/mongodb?
body: <p>Hi I am currently new to nodejs and mongodb what I want to do is make a function to update my win,lose,draw record from my userschema.</p>
  
  <p>My Schema:</p>
  
  <pre><code>UserSchema = new mongoose.Schema({
      username:'string',
      password:'string',
      email:'string',
      //Change Made
      win:{ type: Number, default: 0 },
      lose:{ type: Number, default: 0 },
      draw:{ type: Number, default: 0 }
  });
  
  var db = mongoose.createConnection(app.get('MONGODB_CONN')),
      User = db.model('users', UserSchema);
  </code></pre>
  
  <p>My Function for updating:</p>
  
  <pre><code>app.post('/user/updateScores',function(req, res){
  try{
        var query = req.body.username;
        User.findOneAndUpdate(query, { win : req.body.win, lose : req.body.lose, draw : req.body.draw }, function (err,user){
             if (err) res.json(err) ;
               req.session.loggedIn = true;
               res.redirect('/user/' + user.username);
        });
      }
      catch(e){
          console.log(e)
      }
    });
  </code></pre>
  
  <p>The problem is when I try updating, it updates the current data BUT goes to a blank page and throws an exception saying:</p>
  
  <pre><code>ReferenceError: win is not defined
      at eval (eval at &lt;anonymous&gt; (C:\Users\ryan-utb\Desktop\RockScissorsPaper\node_modules\underscore\underscore.js:1176:16), &lt;anonymous&gt;:5:9)
      at template (C:\Users\ryan-utb\Desktop\RockScissorsPaper\node_modules\underscore\underscore.js:1184:21)
      at Function.exports.underscore.render (C:\Users\ryan-utb\Desktop\RockScissorsPaper\node_modules\consolidate\lib\consolidate.js:410:14)
      at C:\Users\ryan-utb\Desktop\RockScissorsPaper\node_modules\consolidate\lib\consolidate.js:106:23
      at C:\Users\ryan-utb\Desktop\RockScissorsPaper\node_modules\consolidate\lib\consolidate.js:90:5
      at fs.js:266:14
      at Object.oncomplete (fs.js:107:15)
  </code></pre>
  
  <p>but I already defined win properly, what seems to be the problem?</p>