डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

Full Stack Web Development with Laravel

Full Stack Web Development with Laravel

Affiliate Program

Affiliate Program

Aggregation in MongoDB

Aggregation in MongoDB is a framework for performing data processing and transformation operations on documents within a collection. The aggregation framework is built on top of the concept of a pipeline, which is a sequence of stages that process the documents in a collection one by one.
 
Each stage in the pipeline applies a specific operation to the documents and passes the result of that operation to the next stage in the pipeline. The output of the final stage in the pipeline is the result of the entire aggregation operation.
 
The aggregation framework provides a wide range of operators and expressions that can be used in the pipeline stages to manipulate and transform data. Some of the most commonly used pipeline stages and operators include:
 
  1. $match: Filters the documents in the collection based on a specified condition.
  2. $group: Groups the documents in the collection based on a specified key and calculates aggregate values for each group.
  3. $project: Transforms the documents in the collection by selecting, adding, or removing fields.
  4. $sort: Sorts the documents in the collection based on one or more fields.
  5. $limit: Limits the number of documents in the output of the pipeline.
  6. $skip: Skips a specified number of documents in the pipeline.
  7. $lookup: Performs a left outer join with another collection and combines the matching documents into a single result.

Example for mongoDB aggregation

db.products.aggregate([
{
$match:{
    category_id:ObjectId("6152e51f6d9181e969d34fa8")
}
},
{
$project:{
   product_name:1,
   sale_price:1,
   quantity:1
}
},
{
$skip: 1
},
{
$limit:1
}
]);
© 2016 - 2023, All Rights are Reserved.