<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: MD AL-AMIN</title>
    <description>The latest articles on Forem by MD AL-AMIN (@alamincoding).</description>
    <link>https://forem.com/alamincoding</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3731199%2F87efd9bc-cc65-4961-9a5a-5a40f11ce4f8.jpeg</url>
      <title>Forem: MD AL-AMIN</title>
      <link>https://forem.com/alamincoding</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alamincoding"/>
    <language>en</language>
    <item>
      <title>MongoDB Aggregation Pipeline – Practical 3‑Day Guide (Basics to Advanced)</title>
      <dc:creator>MD AL-AMIN</dc:creator>
      <pubDate>Sun, 25 Jan 2026 11:22:24 +0000</pubDate>
      <link>https://forem.com/alamincoding/mongodb-aggregation-pipeline-practical-3-day-guide-basics-to-advanced-18ce</link>
      <guid>https://forem.com/alamincoding/mongodb-aggregation-pipeline-practical-3-day-guide-basics-to-advanced-18ce</guid>
      <description>&lt;p&gt;MongoDB isn't just about storing data — it's about efficiently querying, analyzing, and managing it in real-world applications. Whether you're building an e-commerce platform, analytics dashboard, or content management system, mastering daily MongoDB operations is crucial.&lt;/p&gt;

&lt;p&gt;This 3-day intensive guide is designed to take you from basic queries to advanced real-world scenarios that you'll encounter every day as a developer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Getting Started – Sample Data Setup
&lt;/h2&gt;

&lt;p&gt;Before we dive in, let's set up a realistic database that mirrors real-world applications. We'll create an e-commerce database with users, products, and orders.&lt;br&gt;
📁 users.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  { "_id": 1, "firstName": "Sadat Shahriar", "lastName": "Rafin", "email": "rafin@example.com", "age": 24, "city": "Dhaka", "country": "Bangladesh", "role": "admin", "joinDate": { "$date": "2024-01-15T00:00:00Z" } },
  { "_id": 2, "firstName": "MD. EASIN", "lastName": "AHMED", "email": "easin@example.com", "age": 27, "city": "Chittagong", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-02-20T00:00:00Z" } },
  { "_id": 3, "firstName": "MD RANJU", "lastName": "HASAN", "email": "ranju@example.com", "age": 30, "city": "Dhaka", "country": "Bangladesh", "role": "moderator", "joinDate": { "$date": "2024-03-10T00:00:00Z" } },
  { "_id": 4, "firstName": "MD. Rakibul Islam", "lastName": "Nayon", "email": "nayon@example.com", "age": 22, "city": "Sylhet", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-04-05T00:00:00Z" } },
  { "_id": 5, "firstName": "Md.", "lastName": "Redwan", "email": "redwan@example.com", "age": 35, "city": "Rajshahi", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-01-25T00:00:00Z" } },
  { "_id": 6, "firstName": "Rezwana", "lastName": "Sharmin", "email": "rezwana@example.com", "age": 28, "city": "Khulna", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-05-15T00:00:00Z" } },
  { "_id": 7, "firstName": "Golam Kibria", "lastName": "Hassan", "email": "kibria@example.com", "age": 26, "city": "Dhaka", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-06-10T00:00:00Z" } },
  { "_id": 8, "firstName": "Sumon", "lastName": "Mia", "email": "sumon@example.com", "age": 29, "city": "Barishal", "country": "Bangladesh", "role": "moderator", "joinDate": { "$date": "2024-03-20T00:00:00Z" } },
  { "_id": 9, "firstName": "MD. JOBAYER HOSSAIN", "lastName": "CHOWDHURY", "email": "jobayer@example.com", "age": 31, "city": "Comilla", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-02-15T00:00:00Z" } },
  { "_id": 10, "firstName": "Eahea Bin", "lastName": "Ayub", "email": "ayub@example.com", "age": 25, "city": "Dhaka", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-07-01T00:00:00Z" } },
  { "_id": 11, "firstName": "Md. Abtahi", "lastName": "Abid", "email": "abid@example.com", "age": 23, "city": "Mymensingh", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-04-22T00:00:00Z" } },
  { "_id": 12, "firstName": "Khandaker Rafidul", "lastName": "Haque", "email": "rafidul@example.com", "age": 33, "city": "Sylhet", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-01-10T00:00:00Z" } },
  { "_id": 13, "firstName": "Md. Nuruz Jaman", "lastName": "Nishat", "email": "nishat@example.com", "age": 27, "city": "Rangpur", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-05-05T00:00:00Z" } },
  { "_id": 14, "firstName": "Robiul", "lastName": "Hasan", "email": "robiul@example.com", "age": 28, "city": "Dhaka", "country": "Bangladesh", "role": "user", "joinDate": { "$date": "2024-03-30T00:00:00Z" } },
  { "_id": 15, "firstName": "Md. Atiqur", "lastName": "Rahman", "email": "atiqur@example.com", "age": 32, "city": "Chittagong", "country": "Bangladesh", "role": "moderator", "joinDate": { "$date": "2024-02-28T00:00:00Z" } }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📁 products.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  { "_id": 101, "name": "Laptop Pro 15", "category": "Electronics", "price": 85000, "stock": 15, "tags": ["tech", "office", "premium"], "rating": 4.5 },
  { "_id": 102, "name": "Smartphone X", "category": "Electronics", "price": 45000, "stock": 30, "tags": ["tech", "mobile"], "rating": 4.2 },
  { "_id": 103, "name": "Coffee Maker Deluxe", "category": "Home", "price": 3500, "stock": 20, "tags": ["home", "kitchen"], "rating": 4.0 },
  { "_id": 104, "name": "Gaming Chair RGB", "category": "Furniture", "price": 12000, "stock": 8, "tags": ["tech", "furniture", "gaming"], "rating": 4.7 },
  { "_id": 105, "name": "Wireless Headphones", "category": "Electronics", "price": 2500, "stock": 50, "tags": ["tech", "music"], "rating": 4.3 },
  { "_id": 106, "name": "Smart Watch Pro", "category": "Electronics", "price": 15000, "stock": 25, "tags": ["tech", "wearable"], "rating": 4.6 },
  { "_id": 107, "name": "Desk Lamp LED", "category": "Home", "price": 1500, "stock": 40, "tags": ["home", "office"], "rating": 4.1 },
  { "_id": 108, "name": "Mechanical Keyboard", "category": "Electronics", "price": 5000, "stock": 18, "tags": ["tech", "gaming"], "rating": 4.4 },
  { "_id": 109, "name": "Office Desk", "category": "Furniture", "price": 18000, "stock": 12, "tags": ["furniture", "office"], "rating": 4.5 },
  { "_id": 110, "name": "Bluetooth Speaker", "category": "Electronics", "price": 3000, "stock": 35, "tags": ["tech", "music"], "rating": 4.2 }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📁 orders.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  { "_id": 201, "userId": 1, "items": [{"productId": 101, "qty": 1, "price": 85000}], "total": 85000, "status": "delivered", "orderDate": { "$date": "2025-01-10T00:00:00Z" } },
  { "_id": 202, "userId": 2, "items": [{"productId": 103, "qty": 2, "price": 3500}], "total": 7000, "status": "pending", "orderDate": { "$date": "2025-01-15T00:00:00Z" } },
  { "_id": 203, "userId": 3, "items": [{"productId": 102, "qty": 1, "price": 45000}, {"productId": 105, "qty": 1, "price": 2500}], "total": 47500, "status": "shipped", "orderDate": { "$date": "2025-01-12T00:00:00Z" } },
  { "_id": 204, "userId": 1, "items": [{"productId": 104, "qty": 1, "price": 12000}], "total": 12000, "status": "delivered", "orderDate": { "$date": "2025-01-08T00:00:00Z" } },
  { "_id": 205, "userId": 4, "items": [{"productId": 105, "qty": 3, "price": 2500}], "total": 7500, "status": "processing", "orderDate": { "$date": "2025-01-18T00:00:00Z" } },
  { "_id": 206, "userId": 5, "items": [{"productId": 106, "qty": 1, "price": 15000}], "total": 15000, "status": "delivered", "orderDate": { "$date": "2025-01-05T00:00:00Z" } },
  { "_id": 207, "userId": 6, "items": [{"productId": 107, "qty": 2, "price": 1500}], "total": 3000, "status": "shipped", "orderDate": { "$date": "2025-01-20T00:00:00Z" } },
  { "_id": 208, "userId": 7, "items": [{"productId": 108, "qty": 1, "price": 5000}], "total": 5000, "status": "pending", "orderDate": { "$date": "2025-01-22T00:00:00Z" } },
  { "_id": 209, "userId": 8, "items": [{"productId": 109, "qty": 1, "price": 18000}], "total": 18000, "status": "delivered", "orderDate": { "$date": "2025-01-07T00:00:00Z" } },
  { "_id": 210, "userId": 9, "items": [{"productId": 110, "qty": 2, "price": 3000}], "total": 6000, "status": "shipped", "orderDate": { "$date": "2025-01-14T00:00:00Z" } },
  { "_id": 211, "userId": 10, "items": [{"productId": 102, "qty": 1, "price": 45000}], "total": 45000, "status": "processing", "orderDate": { "$date": "2025-01-19T00:00:00Z" } },
  { "_id": 212, "userId": 11, "items": [{"productId": 105, "qty": 1, "price": 2500}], "total": 2500, "status": "delivered", "orderDate": { "$date": "2025-01-11T00:00:00Z" } },
  { "_id": 213, "userId": 12, "items": [{"productId": 106, "qty": 1, "price": 15000}, {"productId": 108, "qty": 1, "price": 5000}], "total": 20000, "status": "shipped", "orderDate": { "$date": "2025-01-16T00:00:00Z" } },
  { "_id": 214, "userId": 13, "items": [{"productId": 103, "qty": 1, "price": 3500}], "total": 3500, "status": "pending", "orderDate": { "$date": "2025-01-21T00:00:00Z" } },
  { "_id": 215, "userId": 14, "items": [{"productId": 101, "qty": 1, "price": 85000}], "total": 85000, "status": "processing", "orderDate": { "$date": "2025-01-17T00:00:00Z" } }
]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to Import Data&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Using MongoDB Shell:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mongoimport --db ecommerce --collection users --file users.json --jsonArray
mongoimport --db ecommerce --collection products --file products.json --jsonArray
mongoimport --db ecommerce --collection orders --file orders.json --jsonArray
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using MongoDB Compass:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new database called ecommerce&lt;/li&gt;
&lt;li&gt;Create collections: users, products, orders&lt;/li&gt;
&lt;li&gt;Import JSON files into respective collections&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Verify Import:&lt;br&gt;
&lt;code&gt;use ecommerce&lt;br&gt;
db.users.countDocuments()    // Should return 15&lt;br&gt;
db.products.countDocuments() // Should return 10&lt;br&gt;
db.orders.countDocuments()   // Should return 15&lt;/code&gt;&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>mongoose</category>
      <category>database</category>
      <category>aggregation</category>
    </item>
  </channel>
</rss>
