Updating Reference Along With Other Values Mongoose
<p>Here is a schema that I am working on.</p>

<pre><code>var testSchema = mongoose.Schema({ 
    userCreated : {
        type :  mongoose.Schema.Types.ObjectId,
        ref : "User"
    },
    points : {type: Number, default: 0},
    numVotes : {type: Number, default: 0},
    createdAt : Date,
    updatedAt : Date,
}, { timestamps : true });
</code></pre>

<p>Now, I am trying to write a function that will increment two fields on this document (<code>points</code> and <code>numVotes</code>, as well as an additional <code>points</code> field that exists on the user schema.</p>

<p>Here is my attempt.</p>

<pre><code>testSchema.statics.incrementTest = function(id, ...) {
    this.findByIdAndUpdate(id, {$inc : {
        points : 5, 
        numVotes : 1, 
        'userCreated.points' : 5
    }}).exec();
}
</code></pre>

<p>Now, this code that I have written does not work. However, when I comment out the <code>'userCreated.points' : 5</code> line, the other two fields do increment as expected. My question is, what is the best way using mongoose to update the fields on a document and the fields on a subdocument at the same time? </p>