Articles → MONGODB → $First And $Last Aggregation Operators In Mongodb
$First And $Last Aggregation Operators In Mongodb
Purpose
Example
db.orders.aggregate([
{
$group: {
_id: "$customerId",
firstOrderId: { $first: "$_id" }
}
}
])
db.orders.aggregate([
{
$group: {
_id: "$customerId",
firstOrderId: { $last: "$_id" }
}
}
])