db.getCollection(‘notification’).find({},{statusList:{$slice:-1}})
this query is getting expected outputs but from java, I could not find the solution for this. can anyone have a solution for this? I want to use only the aggregation function
db.getCollection(‘notification’).find({},{statusList:{$slice:-1}})
this query is getting expected outputs but from java, I could not find the solution for this. can anyone have a solution for this? I want to use only the aggregation function
3
Answers
the aggregation operator $last can be used to access the last element of an array:
or
and you can also take reference from:
MongoDB – Query on the last element of an array?
Try to use
$last
aggregation operator.Try with this, It gives the same output as $last: