How to troubleshoot a mongoose object save?


I have a node.js api built out that updates a subdocument. Below is the post call for the subdocument:

.put(function(req, res) {
  member.findById(req.params.member_id, function(err, member) {
    if (err)
      res.send(err);

    console.log("old: " + member);

    member.address[req.params.address_id].address_type = req.body.address_type;
    member.address[req.params.address_id].street1 = req.body.street1;
    member.address[req.params.address_id].street2 = req.body.street2;
    member.address[req.params.address_id].City = req.body.City;
    member.address[req.params.address_id].State = req.body.State;
    member.address[req.params.address_id].Zip = req.body.Zip;
    member.address[req.params.address_id].Lat = req.body.Lat;
    member.address[req.params.address_id].Lng = req.body.Lng;

    console.log("new:  " + member);

    member.save(function(err) {
      if (err)
        res.send(err);

      res.json({message:'Address Updated!!!'});
    })
  })
})

The two console.log lines prove that the object was found in the findById call, then updated after going through the array. The logs prove that the object in memory is in fact updated.

However, when actioning the .save() call, I get the success message, but nothing changes in mongodb.

I get no errors, no warnings, nothing. It says success, but no change. How do I troubleshoot?

here's my Address Model:

var mongoose = require('mongoose'),
  Schema = mongoose.Schema

var AddressSchema = Schema({
  Address_type : String,
  street1 : String,
  street2 : String,
  City : String,
  State : String,
  Zip : Number,
  Lat : Number,
  Lng : Number
});


module.exports = mongoose.model('Address', AddressSchema);

and here's the parent model, member:

var mongoose = require('mongoose'),
  Schema = mongoose.Schema

var Address = require('./address');
var Award = require('./award');

var MemberSchema = Schema({
  FName : String,
  LName : String,
  address: [Address.Schema],
  phone : {
    type : String,
    number : String
  },
  email: String,
  gender: String,
  DOB: Date,
  rank : {
    level : String,
    updated: { type: Date, default: Date.now }
  },
  Awards : {
    personal : Boolean,
    award : [Award.Schema],
    granted: { type: Date, default: Date.now }
  }
});


module.exports = mongoose.model('Member', MemberSchema);

When you update an array element of a Mongoose document via its index it doesn't trigger the change detection of the array so Mongoose doesn't know to save it (see the FAQ).

To manually trigger the change detection, you can call markModified before your call to member.save:

member.markModified('address');

To help troubleshoot these types of problems, enable Mongoose's debug output to see the actual calls it's making to the native driver by adding the following to your startup code:

mongoose.set('debug', true);