<?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: CALVIN JOB PURAM</title>
    <description>The latest articles on DEV Community by CALVIN JOB PURAM (@cpuram1).</description>
    <link>https://dev.to/cpuram1</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%2F257826%2F0aeec7db-e2f9-4d79-9d60-2035b9c4059d.jpg</url>
      <title>DEV Community: CALVIN JOB PURAM</title>
      <link>https://dev.to/cpuram1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cpuram1"/>
    <language>en</language>
    <item>
      <title>The Beginner's Guide To MongoDB Aggregation Pipeline Part 1</title>
      <dc:creator>CALVIN JOB PURAM</dc:creator>
      <pubDate>Wed, 29 Jan 2020 15:46:53 +0000</pubDate>
      <link>https://dev.to/cpuram1/the-beginner-s-guide-to-mongodb-aggregation-pipeline-part-1-5c0a</link>
      <guid>https://dev.to/cpuram1/the-beginner-s-guide-to-mongodb-aggregation-pipeline-part-1-5c0a</guid>
      <description>&lt;p&gt;In this series, I will try to demystify the MongoDB Aggregation framework which is a powerful tool that MongoDB offers and gives you great instruments to work with documents in your collection. Using the aggregation framework, you can easily group documents in your collection by specific conditions. you can also add additional fields during grouping such as average, total, minimum, maximum and so on. You can process documents in your collection in several stages one by one. Aggregation request is very fast and you can get results very quickly. I will start this series with some theoretical stuff to aid our understanding before we dive into looking at some examples. We will look into different aggregation requests on our collections and you will see the full power of the MongoDB aggregation framework.&lt;/p&gt;

&lt;p&gt;We need a sample collection to perform this aggregation requests. I have provided an array of documents &lt;a href="https://gist.github.com/calvin-puram/9941f11d0359cc0ba81e52727ce625fd"&gt;Here&lt;/a&gt; which you can copy the documents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.names.insertMany(documents)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;make sure you create a database run the above command replace the "documents" with the array of data you copy from the gist. I will assume that you have worked with MongoDB performing basic CRUD operations, and you have MongoDB setup and installed in your system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Aggregation Process
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WPtPn2Sw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mwzsk8v2osi67gbvmkzx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WPtPn2Sw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mwzsk8v2osi67gbvmkzx.jpg" alt="Alt Text" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suppose we have some documents at the beginning of the aggregation, first we can perform match operation. This match query can produce a subset of the documents. Then, you can take the subset of that document and perform a group operation. As a result of the group operation, you will get brand new documents. These documents are matched and grouped based on certain conditions. for example you may want to match documents based on countries of persons in your collections and you may want to group them based on gender. So in a nutshell aggregation is just like a pipeline in which we have a large set of documents that passes through various stages and these documents get evaluated based on the conditions you placed on them till you have a new set of documents that matched the criteria. This is just a high-level overview. Later in these series, we will dive deeper into details of what it entails.&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>database</category>
      <category>node</category>
    </item>
    <item>
      <title>  A Brief Overview of Mass Assignment in Laravel</title>
      <dc:creator>CALVIN JOB PURAM</dc:creator>
      <pubDate>Thu, 16 Jan 2020 10:06:09 +0000</pubDate>
      <link>https://dev.to/cpuram1/a-brief-overview-of-mass-assignment-in-laravel-1la8</link>
      <guid>https://dev.to/cpuram1/a-brief-overview-of-mass-assignment-in-laravel-1la8</guid>
      <description>&lt;p&gt;Laravel's ORM (Eloquent) provides an extremely easy way to communicate with a database. Each database table has a model class which is used to interact with a table. Most object-relational mappers (ORM) have the ability to mass-assign properties directly into the database, which is a security vulnerability.&lt;/p&gt;

&lt;p&gt;What then is mass assignment? simply it is a process of sending an array of data that will be saved to a specified model at once. Usually, you don't need to save data one by one you can do that in a single process. Mass assignment is something most programmers make use of as it provides a convenient way to populate the properties of a model object from a form. Unfortunately, it's simplicity can make it a target for hackers. What if someone passes a value to the model and without protection they can directly modify all fields including the ID which is not good.&lt;/p&gt;

&lt;p&gt;Let's say we have an 'employee' table which has fields 'first_name, last_name, employee_type' you may want to mass assign 'first_name, last_name' but you may want to protect 'employee_type' from being directly changed. this is where we need &lt;strong&gt;fillable&lt;/strong&gt; and &lt;strong&gt;guarded&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Then is Fillable
&lt;/h3&gt;

&lt;p&gt;Fillable specifies the fields that can be mass assign in your model and this can be achieved by adding a property $fillable in your model as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$fillable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'first_name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'last_name'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="c1"&gt;//only the fields inside this array can be mass-assign&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the 'employee_type' is exempted because we don't want to mass assign it.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Then is Guarded
&lt;/h3&gt;

&lt;p&gt;Guarded is the reverse of fillable which specifies the fields that are not mass assignable. we specify such using a property $guarded in our model class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$guarded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'employee_id'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="c1"&gt;//only the field name inside this array cannot be mass-assignable&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if you want to block all fields from being mass-assign, you can add '*' in your guarded array ad shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Employee&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$guarded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'*'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>php</category>
    </item>
  </channel>
</rss>
