<?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>DEV Community: Iftakhar</title>
    <description>The latest articles on DEV Community by Iftakhar (@iftakhar).</description>
    <link>https://dev.to/iftakhar</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%2F1231840%2F3203a568-bfea-4dfa-902a-aef9fc428029.jpeg</url>
      <title>DEV Community: Iftakhar</title>
      <link>https://dev.to/iftakhar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iftakhar"/>
    <language>en</language>
    <item>
      <title>Client Side Rendering vs Pre Rendering</title>
      <dc:creator>Iftakhar</dc:creator>
      <pubDate>Wed, 12 Mar 2025 17:28:55 +0000</pubDate>
      <link>https://dev.to/iftakhar/client-side-rendering-vs-pre-rendering-3dmn</link>
      <guid>https://dev.to/iftakhar/client-side-rendering-vs-pre-rendering-3dmn</guid>
      <description>&lt;p&gt;(CSR):Client Side Rendering is a web rendering technique where the browser loads a minimal HTML page and dynamically renders content using javaScript ,reducing server load and enabling faster,  interactive user experiences . Client Side Rendering has several challenge &lt;br&gt;
1- Initial Load Time : The initial page load may be slower as the browser has to download and execute javaScript before rendering content &lt;br&gt;
2-SEO-issue : Since Content is rendered dynamically by javaScript , search engines may struggle to index the page effectively,potentially harming SEO&lt;/p&gt;

&lt;p&gt;PreRendering =&amp;gt; When a user prioritizes SEO (Search Engine Optimization), pre-rendering is often used to ensure the content is properly indexed by search engines. Pre-rendering is a technique where the content of the page is generated and served as static HTML, making it easier for search engine bots to crawl and index the page content, even if JavaScript is required to display dynamic elements on the page&lt;/p&gt;

&lt;p&gt;Common Techniques for pre rendering &lt;br&gt;
1- Static Site Generators &lt;br&gt;
2- Server Site Rendering&lt;br&gt;
             Static Side Generators : - Tools like next.js pre-rendered the content at build time,producing static HTML files that are served to both users and search engines . &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         Server Side Rendering. :- This technique involves rendering the page on the server and sending fully rendered HTML to the browser . Frameworks like Next.js also offer SSR for dynamic content
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ssr</category>
      <category>ssg</category>
      <category>clientsiderendering</category>
      <category>prerendering</category>
    </item>
    <item>
      <title>MongoDB Aggregation Pipeline</title>
      <dc:creator>Iftakhar</dc:creator>
      <pubDate>Mon, 09 Dec 2024 09:47:41 +0000</pubDate>
      <link>https://dev.to/iftakhar/mongodb-aggregation-pipeline-26hc</link>
      <guid>https://dev.to/iftakhar/mongodb-aggregation-pipeline-26hc</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Aggregation operation are very important in any type of database whether it is SQL or NoSQL .To perform aggregations operations MongoDB groups values from multiple documents together and then performs a variety of operations on grouped data to return a single result .SQL uses aggregate function to return a  single value calculated from values in columns.&lt;/p&gt;

&lt;p&gt;MongoDB has three ways to perform aggregation: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The aggregation pipeline &lt;/li&gt;
&lt;li&gt;The map reduce Function &lt;/li&gt;
&lt;li&gt;Single purpose aggregation method &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this article we will focus on Aggregation pipeline .&lt;/p&gt;

&lt;h2&gt;
  
  
  Aggregation Pipeline
&lt;/h2&gt;

&lt;p&gt;Aggregation pipelines can have one or more "stages". The order of these stages are important. Each stage acts upon the results of the previous stage.&lt;br&gt;
examples&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.posts.aggregate([
  // Stage 1: Only find documents that have more than 1 like
  {
    $match: { likes: { $gt: 1 } }
  },
  // Stage 2: Group documents by category and sum each categories likes
  {
    $group: { _id: "$category", totalLikes: { $sum: "$likes" } }
  }
])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Various stages in pipeline are
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;$project select, reshape data &lt;/li&gt;
&lt;li&gt;$match filter data &lt;/li&gt;
&lt;li&gt;$group aggregate data &lt;/li&gt;
&lt;li&gt;$sort shorts data&lt;/li&gt;
&lt;li&gt;$skip skips data &lt;/li&gt;
&lt;li&gt;$limit limit data &lt;/li&gt;
&lt;li&gt;$unwind normalizes data &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Stages of pipeline
&lt;/h2&gt;

&lt;h2&gt;
  
  
  $project
&lt;/h2&gt;

&lt;p&gt;in project phase we can added a key ,remove a key , reshape a key.There are some simple functions that we can use on the key $toUpper, $toLower, $add,$multiply etc&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.mycollection.aggregate([{
    $project: {
        _id: 0,
        'department': {
            $toUpper: '$dept_name'
        },
        'new_experience': {
            $add: ['$experience', 1]
        }
    }
}])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  $match
&lt;/h2&gt;

&lt;p&gt;It works exactly like ‘where clause' in SQL to filter out the records. The reason we might want to match, is because we would like to filter the results and only aggregate a portion of the documents or search for particular parts of the results set, after we do the grouping. Let's say, in our collection, we want to aggregate documents having department equals to sales. The query will be.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.mycollection.aggregate([{
    $match: {
        dept_name: 'Sales'
    }
}])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  $group
&lt;/h2&gt;

&lt;p&gt;As the name suggested $group group the document based on some key &lt;br&gt;
,lets say we want to group employs on their department name and we want to find the number of employees in each department .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.mycollection.aggregate([{
    $group: {
        _id: '$dept_name',
        no_of_employees: {
            $sum: 1
        }
    }
}])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  $sort
&lt;/h2&gt;

&lt;p&gt;Sort helps you to sort the data after aggregation, in ascending or descending order as per your need. Let’s say, we want to group department name in ascending order and find out the number of employees.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.mycollection.aggregate([{
    $group: {
        _id: '$dept_name',
        no_of_employees: {
            $sum: 1
        }
    }
}, {
    $sort: {
        _id: 1
    }
}])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  $skip and $limit
&lt;/h2&gt;

&lt;p&gt;$skip and $limit, as the names suggest, skip and limit work respectively when we do a simple find. It doesn’t make any sense to skip and limit unless we first sort, otherwise, the result is undefined.&lt;/p&gt;

&lt;p&gt;We first skip records and then we limit those.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.mycollection.aggregate([{
    $group: {
        _id: '$dept_name',
        no_of_employees: {
            $sum: 1
        }
    }
}, {
    $sort: {
        _id: 1
    }
}, {
    $skip: 2
}, {
    $limit: 1
}])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  $unwind
&lt;/h2&gt;

&lt;p&gt;As we know in MongoDB, documents can have arrays. It is not easy to group on something within an array. $unwind first un-joins the array data and then basically rejoins it in a way that lets us do grouping calculations on it.&lt;/p&gt;

&lt;p&gt;Let’s say, we have a document like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    a: somedata,
    b: someotherdata,
    c: [arr1, arr2, arr3]
}

After $unwind on‘ c’, we will get three documents.

{
    a: somedata,
    b: someotherdata,
    c: arr1
} {
    a: somedata,
    b: someotherdata,
    c: arr2
} {
    a: somedata,
    b: someotherdata,
    c: arr3
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By mastering these stages, you can harness the full power of MongoDB's aggregation pipeline to analyze and manipulate data efficiently. Let me know if you need further clarification!&lt;/p&gt;

</description>
      <category>aggregation</category>
      <category>mongodb</category>
      <category>pipeline</category>
    </item>
  </channel>
</rss>
