I know that MongoDB supports the syntax find{array.0.field:\"value\"}, but I specifically want to do this for the last element in the array, which means I don\'
find{array.0.field:\"value\"}
Version 3.6 use aggregation to achieve the same.
db.getCollection('deviceTrackerHistory').aggregate([ { $match:{clientId:"12"} }, { $project: { deviceId:1, recent: { $arrayElemAt: [ "$history", -1 ] } } } ])