title: Mongoose findByIdAndUpdate
body: <p>I trying to edit and update a form using mongoose. The code seems fine to me, but it doesn't work. I have tried so many ways but the updated version is still the same, I uses a put route to send the form, when I output req.body.studentInfo to the console, it is correct, but the update remains the same. Please help</p>
  
  <p>This is my schema</p>
  
  <pre><code>var mongoose = require("mongoose");
  var uniqueValidator = require('mongoose-unique-validator');
  var passportLocalMongoose = require("passport-local-mongoose");
  var mongoose = require("mongoose");
  
  var UserSchema = new mongoose.Schema({
     studentInfo: {
     first_name: String,
     middle_name: String,
     last_name: String,
     street: String,
     town: String,
     city: String,
     region: String,
     country: String,
     studentId: String,
     day: Number,
     month: String,
     year: Number,
     },                   
     username: {type: String, required:true, unique:true},
     passport: String
  
  });
  UserSchema.plugin(uniqueValidator);
  UserSchema.plugin(passportLocalMongoose);
  
  module.exports = mongoose.model("StudentInfo", UserSchema);
  </code></pre>
  
  <p>This is my App.js</p>
  
  <pre><code>app.put('/:id', function(req,res){
      StudentInfo.findByIdAndUpdate(req.params.id, {$set: req.body.studentInfo}, function(err, updated){
          console.log(req.params.id);
          console.log(req.body.studentInfo);
          if(err) {
              console.log(err);
          }
          else {
              res.redirect('/' + req.params.id);
          }
      });
  
  });
  
  The studentInfo is an object that contains the names of each variables in my form which I name was studentInfo[name of variable]. Please help
  </code></pre>