Insert value into array element in an array element and return array length
<p>I would like to add a value to an a field which lies within an array element, I would also like the amount of elements in the array to be returned and also that only one value is allowed to be input. below is the data:</p>

<pre><code>{
    "_id" : ObjectId("56bb59beb32fa53064f51e3f"),
    "title" : "okok",
    "views" : 1,
    "messages" : [
        {
            "authorId" : ObjectId("56bb599e8f308f1664c93011"),
            "upvotes" : [], // &lt;--- want to push a value here
            "created" : ISODate("2016-02-10T15:39:42.006Z"),
            "updated" : ISODate("2016-02-10T15:39:42.006Z"),
            "message" : "okok"
        },
        {
            "authorId" : ObjectId("56bb599e8f308f1664c93010"),
            "upvotes" : [], // &lt;--- insert into here plz
            "created" : ISODate("2016-02-10T15:39:47.170Z"),
            "updated" : ISODate("2016-02-10T15:39:47.170Z"),
            "message" : "uhuhuh"
        },
        {
            "authorId" : ObjectId("56bb599e8f308f1664c93011"),
            "upvotes" : [],
            "created" : ISODate("2016-02-10T15:40:01.772Z"),
            "updated" : ISODate("2016-02-10T15:40:01.772Z"),
            "message" : "åpåpå"
        },
        {
            "authorId" : ObjectId("56bb599e8f308f1664c93010"),
            "upvotes" : [],
            "created" : ISODate("2016-02-10T15:40:04.889Z"),
            "updated" : ISODate("2016-02-10T15:40:04.889Z"),
            "message" : "påpåpå&lt;br /&gt;&lt;br /&gt;påå"
        },
        {
            "authorId" : ObjectId("56bb599e8f308f1664c93010"),
            "upvotes" : [],
            "created" : ISODate("2016-02-11T12:36:26.006Z"),
            "updated" : ISODate("2016-02-11T12:36:26.006Z"),
            "message" : "testt"
        },
        {
            "authorId" : ObjectId("56bb599e8f308f1664c93013"),
            "upvotes" : [],
            "created" : ISODate("2016-02-11T12:36:31.514Z"),
            "updated" : ISODate("2016-02-11T12:36:31.514Z"),
            "message" : "tetetet"
        }
    ]
}
</code></pre>

<p>I have the document <code>_id</code> and the array element <code>created</code> field to locate the element in the array.</p>

<p>I tried the following:</p>

<pre><code>}  
    $match: {
        _id: retard.ObjectId(data.id),
        'messages.created': data.created
    }
}, {
    $group: {
        'messages.$.upvotes': {
            $addToSet: 'myTestValueToInsert'
        }
    }
}, {
    $project: {
        numUpvotes: {
            $size: '$upvotes'
        }
    }
}, {
    multi: false
}
</code></pre>

<p>However getting an error. I've been reading the aggregation documentation but the examples are slightly lacking!</p>