I have this code:
balanceModel.findOne({year: parseInt(req.params.year)},function(err,data){
data.months['weirdber'] = {
x: 'y'
};
data.save(function(e,d){
console.dir(e);
res.json(d);
});
});
null
is printed when I call it, so definitely no error is thrown.
The callback's d
argument holds the correct data, including the newly added property.
Yet, when I retrieve the collection later, there is no property 1999
in years
.
I have mad absolutely sure that I do not retrieve the wrong collection later on.
This is my Schema, which I have cut down from a compley one with nested schemas to this, let's call it super simple to avoid bad words, stuff. Still not working.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var BalanceSchema = new Schema({
year: Number,
months: Object
});
module.exports = mongoose.model('Balance', BalanceSchema);
What is going on here?