LearnBoost/mongoose — Issue #699: strict: true not working when doing an update
Author: andersmattson
Created: 2012-01-27 10:22:13+00:00
State: open

Not sure wether this is an issue or a feature request, but it seems `strict: true` isn't working when doing an update to a model:

```javascript
// Define a schema with strict: true
var TestSchema = new Schema({
name: String,
desc: String
}, {strict: true});

// Add the model
mongoose.model("testmodel", TestSchema);

var model = mongoose.model('testmodel');

var doc = new model();
doc.name = "should be saved";
doc.generic1 = "this should not be saved";

// Test when creating and updating a newly created
doc.save(function(err) {
model.update({ _id: doc._id }, { generic2: 'should not be saved' }, function(err) {
model.findById(doc._id, function(err, saveddoc) {

// saveddoc.generic1 is undefined as it should be but
// saveddoc.generic2 is set to 'should not be saved'.
console.log("Test #1:", saveddoc);

});
});
});

// Test with an existing
model.update({ _id: '4f2277b2dc4fbaf4fc000003' }, { generic3: 'should not be saved' }, function(err) {
model.findById('4f2277b2dc4fbaf4fc000003', function(err, saveddoc) {

// saveddoc.generic3 is set to 'should not be saved'.
console.log("Test #2", saveddoc);

});
});
```