LearnBoost/mongoose — Issue #557: Middleware broken on embedded docs
Author: jnordberg
Created: 2011-10-08 00:42:01+00:00
State: open

Trying to update a document with an embedded doc that has a middleware produces a `MongoError: have conflicting mods in update`

To reproduce:

```javascript
var mongoose = require('mongoose'),
Schema = mongoose.Schema;

mongoose.connect('mongodb://localhost/test');

var UserSchema = new Schema({
username: String
});

// works if this middleware is removed
UserSchema.pre('save', function(next) {
this.username += 'bar';
next();
});

var GroupSchema = new Schema({
users: [UserSchema]
});

var Group = mongoose.model('Group', GroupSchema);

var group = new Group();
group.users.push({username: 'foo'});
group.save(function(error) {
if (error) throw error;
Group.findById(group._id, function(error, result) {
if (error) throw error;
result.users.push({username: 'candy'});
result.save(function(error) {
if (error) throw error; // MongoError: have conflicting mods in update
console.log(arguments);
});
});
});

```