When I modify value of date field, and call save method, then model object's value is modified, but value isn't saved in database.
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/tests');
var Model = new mongoose.Schema({ date : Date });
var M = mongoose.model('Model', Model);
function log(date) {
return console.log(date.getFullYear() + '-'
+ (date.getMonth() + 1) + '-'
+ date.getDate());
}
M.create({ date: new Date('2013-01-01') }, function(err, m) {
log(m.date); //=> 2013-1-1
var date = m.date;
date.setMonth(date.getMonth() + 1);
m.date = date;
// month is modified
log(m.date); //=> 2013-2-1
m.save(function(err, m2) {
// month is modified
log(m2.date); //=> 2013-02-01
M.findById(m2._id, function(err, m3) {
// month is **not** modified
log(m3.date); //=> 2013-01-01
process.exit();
});
});
});
I think the value that is passed to save method should always be equal to the value of database.
m.save(function(err, m2) {
M.findById(m2._id, function(err, m3) {
expect(m2).to.eql(m3);
});
});
versions:
- mongoose: 3.6.15
- mongodb: 2.0.6
When I modify value of
datefield, and callsavemethod, then model object's value is modified, but value isn't saved in database.I think the value that is passed to
savemethod should always be equal to the value of database.versions: