$arrayElemAt new in MongoDB version 3.2.
db.users.aggregate([
{
$project:
{
name: 1,
first: { $arrayElemAt: [ "$favorites", 0 ] },
last: { $arrayElemAt: [ "$favorites", -1 ] }
}
}
])
you can now use $arrayElemAt
with ArrayOperators.ArrayElemAt class.
The above MongoDB projection would be traduced like the following for Spring Data Mongo:
project("name")
.and(ArrayOperators.ArrayElemAt.arrayOf("favorites").elementAt(0)).as("first")
.and(ArrayOperators.ArrayElemAt.arrayOf("favorites").elementAt(-1)).as("last")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With