I want to find documents where last elements in an array equals to some value. Array elements may be accessed by specific array position:
// i.e. comments[0]
I'm just doing :
db.products.find({'statusHistory.status':'AVAILABLE'},{'statusHistory': {$slice: -1}})
This gets me products for which the last statusHistory item in the array, contains the property status='AVAILABLE' .
products
statusHistory
status='AVAILABLE'