var Assignment =mongoose.model('Assignment', { dueDate: Date });Assignment.findOne(function (err, doc) {doc.dueDate.setMonth(3);doc.save(callback); // THIS DOES NOT SAVE YOUR CHANGEdoc.markModified('dueDate');doc.save(callback); // works})
person.anything = { x: [3,4, { y:"changed" }] };person.markModified('anything');person.save(); // anything will now get saved
ObjectIds
指定一个ObjectId类型,使用Schema.Types。ObjectId在你的声明中。
var mongoose =require('mongoose');var ObjectId =mongoose.Schema.Types.ObjectId;var Car =newSchema({ driver: ObjectId });// or just Schema.ObjectId for backwards compatibility with v2