LearnBoost/mongoose — Issue #687: $inc doesn't work with an array of embedded documents.
Author: tsantosvgl
Created: 2012-01-17 17:51:49+00:00
State: open

Trying to increment a embedded doc array item property

The code:
```javascript
var MySubSchema = new Schema({
txt:String,
v:Number
});

var MySchema = new Schema({
ptr:String,
txt:String,
obj:{
info:String,
all:[MySubSchema]
}
});

var MyModel = mongoose.model('MyModel', MySchema, 'mycollection');

var where = {'ptr':'123', 'txt':'foo', 'obj.all.txt':'bla'};
var update = {'$inc':{'obj.all.$.v':1}};

MyModel.update(where, update, function(err){
console.log(err);
});
```

The result:

err: { stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'can\'t append to array using string field name [$]',
name: 'MongoError',
err: 'can\'t append to array using string field name [$]',
code: 13048,
n: 0,
ok: 1 }