Articles → MONGODB → $Slice Operator In Mongodb Aggregation Framework
$Slice Operator In Mongodb Aggregation Framework
Purpose
Syntax
{
$project: {
fieldName: {
$slice: [arrayField, numberOfElements]
}
}
}
Example
db.sales.aggregate([{
$project: {
slicedOrders: {
$slice: ["$orders", 1]
}
}
}])
Output