Sunday, June 23, 2024

Complex aggregation queries Mongodb - Examples

 Group and slice array

@Aggregation(pipeline = {
"{ $match: {'category':{$regex : ?0, $options: 'i'}}}",
"{ $group: { _id: {category:'$category'}, data: { $push: '$$ROOT' } } }",
"{ $project: { _id: 0, category:'$_id.category', videos:{ $slice:['$data',?1,?2]} }"

})

No comments:

Post a Comment