Without a known length for the array, you cannot reference the last element of the array using the "array.i" syntax. There are other ways of maintaining the array that might allow you to accomplish what you want to do anyway:
1. Use $push with $each and $position to insert elements to the front of the array, then reference array.0:
> db.test.drop()
> db.test.insert({ "_id" : 0, "x" : [1, 2, 3] })
> db.test.update({ "_id" : 0 }, { "$push" : { "x" : { "$each" : [4], "$position" : 0 } } })
> db.test.findOne()
{ "_id" : 0, "x" : [ 4, 1, 2, 3 ] }
> db.test.count({ "x.0" : 4 })
1
$position is new in 2.6.
2. Use $push with $each and $sort to maintain the array in a sorted order to that your current last element appears first:
> db.test.drop()
> db.test.insert({ "_id" : 0, "x" : [1, 2, 3] })
> db.test.update({ "_id" : 0 }, { "$push" : { "x" : { "$each" : [0], "$sort" : 1 } } })
> db.test.findOne()
{ "_id" : 0, "x" : [ 4, 1, 2, 3 ] }
> db.test.count({ "x.0" : 0 })
1
This works only if some `$sort` works for your use case, naturally.
3. Maintain the last value pushed onto the array in a separate field:
> db.test.drop()
> db.test.insert({ "_id" : 0, "x" : [1, 2, 3], "last" : 3 })
> db.test.update({ "_id" : 0 }, { "$push" : { "x" : 4 }, "$set" : { "last" : 4 } })
> db.test.findOne()
{ "_id" : 0, "x" : [ 1, 2, 3, 4 ] }
> db.test.count({ "last" : 4 })
1
-Will