MongoDB Crud Operation and Mongo DB Crud

MongoDB Crud Operation

MongoDB Crud Operation Basics


Create studentInfo Database in MongoDB server. Use the below code for creating the DB.


Above use studentInfo command will create the DB in MongoDB Server. If studentInfo DB will exist then it will switch to that instead of creating it. To view the created database in the list you must have to create at least one collection in that.

MongoDB provide db.createCollection() method to create collection in database. Command to create studnet collection in studentInfo Database is below 


Press Enter collection will be created in studentInfo Database with the name of student. To view all the collection in the studentInfo Database use below command. Below command will list all the collection present in the studentInfo Database. 

Insert or Create Document in MongoDb Collection


To insert document in the collection in MongoDB Database. We use below two command to insert the document.

  • db.collectionName.insertOne()
  • db.collectionName.insertMany()

Using above two method we will insert the document in the student Collection of studentInfo Database. 

This below command will insert one document in student Collection.

db.student.insertOne(
   { 
     "id":1,
     "name":"Manoj Kumar",
     "dob":"2003-04-07",
     "marks":54,
     "created_at":"2017-11-13 23:33:42"
   }
)

To Insert many document at a time we have to use db.collectionName.insertMany() method . Below is the code for inserting many document at a time. We can pass all the document as a array.

db.student.insertMany([
   { 
     "id":2,
     "name":"MOHAMMED  H",
     "dob":"2002-06-14",
     "marks":67,
     "created_at":"2016-11-13 23:33:42"
   },
   { 
     "id":3,
     "name":"ANBUSELVAM S",
     "dob":"2004-06-18",
     "marks":87,
     "created_at":"2019-11-13 23:33:42"
   }
 ])



Fetch Or Retrieve Document from Collection


To retrieve or fetch the document from the MongoDB collection we use db.collectionName.find() method.
  • db.student.find() method will fetch all the document from the specified MongoDB collection. This above method will fetch all the document in single line which will not be in readable format.
  • db.student.find().pretty() method will fetch and arrange the collection document in some proper readable format. pretty() method will give you the output is below for reference. 

MongoDB Operators and Query Example


We can apply various filter on mongoDB collection document based on certain condition. We can use various operator also for document filter. Below is the query list and condition to demonstrate the filtration.

$eq (=)
$eq will match the value with specified value.
$gt (>)
$gt will check that the value is greater than specified value.
$gte (>=)
$gte will check that the value is greater than equal to specified Value.
$in (IN)
$in will check that specified value is there in range or not.
$nin (NOTIN)
$nin will check that specified value not lies in the range.
$lt (<)
$lt will check that the value is less than the specified value
$lte (=<)
$lte will check that the value is less than the specified value
$ne (!=)
$ne will check whether the value not equal to specified value


$and
Logical AND join multiple query clause and compare multiple clause and return value as True or False.
$not
Logical NOT Check the query expression and return the result.
$nor
Logical NOR join multiple query clause and compare multiple clause
$or
Logical OR  join multiple query clause and compare multiple clause and return value as True or False

Some Query Example using above operator is below for reference with output.

  •  db.student.find({marks:{$eq:43}}).pretty()     O/P is below                                                                                             
    mongoDB Comparision Operator Example

  • db.student.find({marks :{$gte:70}}).pretty()  O/P is below                                                                                 
    $gte operator in MongoDB

  • db.student.find({marks :{$in:[54, 87]}}).pretty()  O/P is below                                                                         

Query Using AND Logical Operator in MongoDB


  • db.student.find({$and :[{name : "JAGAN J"},{marks :98}]}).pretty()                                               {
            "_id" : ObjectId("5ebeaafd50845b5c0ea8bf58"),
            "id" : 5,
            "name" : "JAGAN J",
            "dob" : "2003-04-10",
            "marks" : 98,
            "created_at" : "2012-11-13 23:33:42"
        }


Query Using OR Logical Operator in MongoDB

  • db.student.find({$or :[{name:"JAGAN J"},{marks :{$gt:70}}]}).pretty()                                     {
            "_id" : ObjectId("5ebeaafd50845b5c0ea8bf56"),
            "id" : 3,
            "name" : "ANBUSELVAM S",
            "dob" : "2004-06-18",
            "marks" : 87,
            "created_at" : "2019-11-13 23:33:42"
    }
    {
            "_id" : ObjectId("5ebeaafd50845b5c0ea8bf58"),
            "id" : 5,
            "name" : "JAGAN J",
            "dob" : "2003-04-10",
            "marks" : 98,
            "created_at" : "2012-11-13 23:33:42"
    }

Query Using AND Operator as well as OR in MongoDB


  • db.student.find({marks :{$lt : 99}, $or :[{marks :{$in:[43,98]}},{name : "JAGAN J"}]}).pretty()                                                                                                                                  {
            "_id" : ObjectId("5ebeaafd50845b5c0ea8bf57"),
            "id" : 4,
            "name" : "MARTINPRIYADOSS J",
            "dob" : "2004-03-08",
            "marks" : 43,
            "created_at" : "2012-11-13 23:33:42"
    }
    {
            "_id" : ObjectId("5ebeaafd50845b5c0ea8bf58"),
            "id" : 5,
            "name" : "JAGAN J",
            "dob" : "2003-04-10",
            "marks" : 98,
            "created_at" : "2012-11-13 23:33:42"
    }

MongoDB Update Query

Update query in MongoDB is done using below method.
  • db.collection.updateOne() 
  • db.collection.updateMany() 
  • db.collection.replaceOne()

Delete Operation In MongoDB

Delete Query in MongoDB is done using below method.
  • db.collection.deleteOne() 
  • db.collection.deleteMany() 

AWS Elastic Load Balancer and ELB and ALB Pricing

AWS ELB and Amazon Elastic Load Balanacer
AWS Load balancer accept all the incoming Application incoming Traffic and distribute to multiple target such as EC2 instance, container etc.. Elastic Load Balancer support various type of Load Balancer.

1) Application Load Balancers
2) Network Load Balancers
3) Classic Load Balancers

   Load Balencer ensure that server resource must be available 24 x 7 without any fault. Amazon ELB ensures fall tolerance and High Availability of server resource. Web Traffic get distributed to the available backend server using AWS ELB. 
    Load Balancer contain mainly three part :- Listner (Which will listen Port), Traget Group and third is Traget.



Load Balancer distribute the traffic request to various server to balance the load more or less equally.
Whatever ( http / https ) request comes to the load balancer based on the server traffic and health status it will divert.



Amazon S3 Bucket Pricing and AWS Bucket Storage


Amazon S3 Bucket
AWS Storage Type

  • S3 (Simple Storage Services) [Object Level Based Storage]
  • EFS (Elastic File System)
  • EBS (Elastic Block Storage)
  • Glacier 
  • Snowball

Amazon S3(Simple Storage Services)

  • Amazon S3 is public storage resource in AWS (Amazon Web Services) Cloud which is object based storage.
  • AWS S3 Bucket is storage same like a file folders which store objects with data and its Metadata.
  • S3 stores all the files (like pdf, images, video, documents etc ) as a object in AWS Cloud. You cannot have the Bucket inside bucket, Bucket can have the folders which groups object inside in it. S3 bucket is having flat architecture (Bucket inside bucket you can't create.).
  • If you want to use AWS S3 services, First you have to create the S3 Bucket in any of the AWS Region. Bucket name is unique Globally. Once Bucket is created it get shared with all the AWS Account. The bucket name cannot be used by any other AWS account.
  • Amazon S3 services comes under IaaS (Infrastructure as a Services). The Important AWS Services which is offered as Iaas is S3 (Simple Storage Service), EC2 (Elastic computing 2)  and RDS (Relational Database Service). These IaaS services is charged per hour basis.
  • We can't Install operating System in S3 Storage.
  • AWS S3 have distributed Data Architecture where copy of data is stored in multiple location within the region.
  • Bucket can store maximum 5TB Data, 100 bucket per aws Account which you can extend further.  
  • S3 Bucket cannot be transferred from one aws account to another AWS account. It can be shared and can be access with multiple location.

S3 Bucket and Naming Rules

  • Bucket name is Globally Unique. In AWS Cloud two bucket can't have the same name. It must be unique.
  • Once the Bucket name is created it cannot be changed. If bucket name is deleted then again it will be available for other user to choose that Bucket name.
  • Bucket name must contain atleaste 3 Character and max 63 Character.
  • Bucket Name is URL part through which we try to access the bucket.
  • Bucket name can be created using lower Case letter, number and hyphen. We cant use Upper case letter while naming the bucket. You cant start and end the bucket name with -(hyphen). Bucket name should not be an IP address.
  • Whenever we create bucket or Object, By default it is private. Only bucket owner can access that.    

S3 Bucket Sub-resources

  • Object Life cycle : In this we can define the object life cycle. We can move the object based on the time frame from one storage type to other storage. this can reduce the cost. See the below image where we are moving the object from one storage to other based on the recent data. 
  • Website : We can use S3 for hosting Static website.
  • Versioning : You can enable the versioning on your storage which will maintain your previous updated file and the current file too. You cant disable the versioning. You can enable or suspend the versioning.
  • Access Control List : In this you can decide the security of your bucket regarding access.

S3 Bucket Versioning

Bucket Versioning help us to recover the data in the case of accidental delete. Suppose you deleted the Data accidentally, to retrieve the data we enable versioning. Versioning maintain the older data as well as the current data. If the versioning is enabled and the object / Data got deleted, in that case you can recover / restore the data easily.

Versioning Help us in data retention as well as data archive. Once you enable the Versioning, you can't disable it. You can suspend it only.

When Versioning is enabled and we delete the object / data , delete marker is placed on the object which we can recover whenever we want.

You will be charged for all the multiple versions. Example Just imagine you have 10 MB file initially, next versioning your file size became 14 MB, again in next versioning it became 18 MB. It will be charged for incremental only which will be 8 MB not for 42 MB. This is incremental versioning.   

You can apply the life-cycle on versioning which means as the object / data become older we can move it to cheaper storage or we can delete the data.

The Object which exist before version enabling will have the version ID Null. 

Multi Factor Authentication (MFA)

MFA is extra level of security which we can apply on our S3 Bucket. By Enabling the Multi-factor authentication you restrict the other users to delete the S3 object accidentally. Once the Multi-factor Authentication is enabled you can delete until unless the security code received by the registered physical device is shared with you within 30 second.  

S3 Multipart Upload

S3 Multipart Upload allow us to upload our file to server in parts. This object parts get uploaded independently and in parallel. You must use the multipart Upload facility to upload the file in the server if the size is equal or greater than 5 gb using Multipart Upload API.

Type of AWS S3 Storage  

1) Amazon S3 Standard [Storage Cost is High but Accessing / Retrieving cost is low. ]
    This Storage is useful if you need data access frequently. 

2) Amazon S3 Glacier Deep Archive  [Storage Cost is cheapest but Retrieving cost is High.]
    Amazon S3 Glacier Deep Archive is suitable when you have rare access to the data(Once in a year or rare access.). As S3 Glacier Deep Archive storage is damm Cheaper but accessing the data cost higher. Accessing Glacier Deep Archive Data takes time which is not fix. 

3) Amazon Glacier
Amazon S3 Glacier is little costlier then Glacier Deep Archive. This also we use when we don't need the data access frequently. Accessing Glacier Data takes time which is not fix. The Main difference between Amazon glacier and Glacier Deep Archive is, in AWS Glacier you have the option to select the data retrieval time. This means you can select the access time if you want to access the data. Three Option Available for data retrieval, you want retrieval within a minute, within a Hour, or within 12 hour.     

4) Amazon S3 Standard Infrequent Access 
Amazon S3 Standard Infrequent Access This storage is best for infrequent access. Sometime you need to access the data and you need it immediately. This storage provide immediate access it don't delay like Amazon Glacier or Amazon S3 Glacier Deep Archive. Overall it is infrequent access of data but whenever it is access data must available immediately without delay.

5) Amazon S3 One Zone - IA
By Default S3 Create three copy of your data and keep it as a back up and charge you accordingly. And in any disaster it will recover your data using other copy. S3 One Zone  allow you to keep only one copy of the data in one zone. In disaster your data is not recoverable. 

6) Amazon S3 Intelligent tearing. 
We use this Intelligent Tearing storage in case of when we dont know whether we are going to access the data immediately or not.

Jammu and Kashmir GK Question- JK General Knowledge

j&k Objective GK Question




  1. Who was the last ruling Maharaja of Jammu and Kashmir
    1. A. Hari Singh       Correct Answer
    2. B. Pratap Singh      
    3. C. Ranbir Singh      
    4. D. Gulab Singh      
  2.  

    The Wular Lake is located in which district
    1. A. Udhampur District     
    2. B. Baramulla District      
    3. C. Bandipora District        Correct Answer
    4. D. Kupwara District      
  3.  

    Which one is recognised as the state flower of J&K
    1. A. Rose     
    2. B. Lily      
    3. C. Lotus        Correct Answer
    4. D. Daisy      
  4.  

    In 1897, first railway line was built in Jammu and Kashmir to connect Jammu with which city
    1. A. Sialkot       Correct Answer
    2. B. Udhampur      
    3. C. Delhi      
    4. D. Rawalpindi      
  5.  

    Which city has the most population in J&K
    1. A. Udhampur     
    2. B. Jammu      
    3. C. Srinagar        Correct Answer
    4. D. Anantnag      
  6.  

    The Shalimar Bagh was built by
    1. A. Shah Jahan     
    2. B. Akbar      
    3. C. Babur      
    4. D. Jahangir        Correct Answer
  7.  

    Srinagar is located on the banks of the
    1. A. Chenab river     
    2. B. Jhelum river        Correct Answer
    3. C. Indus river      
    4. D. Lidder river      
  8.  

    Total number of districts in Jammu and Kashmir
    1. A. 22       Correct Answer
    2. B. 24      
    3. C. 28      
    4. D. 32      
  9.  

    Total number of national parks in Jammu and Kashmir
    1. A. 3     
    2. B. 4      
    3. C. 5        Correct Answer
    4. D. 7      
  10.  

    On which hill, the Vaishno Devi mandir is located
    1. A. Katra     
    2. B. Aru      
    3. C. Trikuta        Correct Answer
    4. D. Sonamarg      
  11.  

    The Shalimar Bagh was built in the year
    1. A. 1606     
    2. B. 1619        Correct Answer
    3. C. 1627      
    4. D. 1635      
  12.  

    Which one is the longest river in Jammu Kashmir
    1. A. Indus River     
    2. B. Jhelum River      
    3. C. Chenab River        Correct Answer
    4. D. Doda River      
  13.  

    The kargil war was fought in the year
    1. A. 1998     
    2. B. 1999        Correct Answer
    3. C. 2000      
    4. D. 2001      
  14.  

    Which one is the largest district in Jammu and Kashmir by areawise
    1. A. Leh       Correct Answer
    2. B. Kargil      
    3. C. Doda      
    4. D. Baramula      
  15.  

    The Hemis National Park is famous for
    1. A. Golden Eagle     
    2. B. Tiger      
    3. C. Wolf      
    4. D. Snow Leopard        Correct Answer
  16.  

    Which article of the Indian constitution give special state status to Jammu and Kashmir
    1. A. Article 120     
    2. B. Article 180      
    3. C. Article 260      
    4. D. Article 370        Correct Answer
  17.  

    Between which mountain ranges is Kashmir Valley located
    1. A. Himadri - Pir Pranjal       Correct Answer
    2. B. Shivalik - Himachal      
    3. C. Karakoram - Himachal      
    4. D. Himadri - Himachal      
  18.  

    Who is the first Chief Minister of Jammu and Kashmir
    1. A. Hari Singh     
    2. B. Syed Mir Qasim      
    3. C. Ghulam Mohammed Sadiq        Correct Answer
    4. D. Sheikh Abdullah      
  19.  

    Total number of Lok Sabha Constituency in Jammu and Kashmir is
    1. A. 4     
    2. B. 6        Correct Answer
    3. C. 8      
    4. D. 9      
  20.  

    Which of the following lakes of India is located in Jammu and Kashmir
    1. A. Phuljhar Lake     
    2. B. Koleru Lake      
    3. C. Anchar Lake        Correct Answer
    4. D. Hamirsar Lake      
  21.  

    Sheikh Abdullah died in the year
    1. A. 1978     
    2. B. 1982        Correct Answer
    3. C. 1985      
    4. D. 1989      
  22.  

    Which town in Jammu Kashmir is also known as Apple Town
    1. A. Sopore       Correct Answer
    2. B. Anantnag      
    3. C. Shupiyan      
    4. D. Jammu      
  23.  

    From which year the Constitution of Jammu and Kashmir implement
    1. A. 1956     
    2. B. 1962      
    3. C. 1963      
    4. D. 1965        Correct Answer

Important jQuery and Javascript Code for Project

JQuery and Javascript Code Snippet


$("#fee_exp").change(function(){
   if ($(this).val() == 'Y') {
     $("#check").removeClass('hide');
     $("#check1").addClass('required');
   }else{
     $("#check").addClass('hide');
     $("#check1").removeClass('required');
   }
});


          function submitform()
              {
                $('#registeration').find('form').submit();
                $('.clearFields').val('');
               }



$('#splitPayment input:radio').change(function() {
    if ($(this).val() === 'Y') {
       $('#accountDetail').removeClass('hide');
       $('#primary_account').addClass('required');
       $('#additional_account').addClass('required');

    } else if ($(this).val() === 'N') {
           $('#accountDetail').addClass('hide');
           $('#primary_account').removeClass('required');
    $('#additional_account').removeClass('required');
    $('#primary_account').val("");
    $('#additional_account').val("");
    }
 });



/*Input Field Validation */

 $(".nameclass").on('input', function(event) {
  var regexp = /[^a-zA-Z @]/g;
   if($(this).val().match(regexp)){
     $(this).val( $(this).val().replace(regexp,'') );
   }
 });

 $(".initials").on('input', function(event) {
  var regexp = /[^a-zA-Z .]/g;
   if($(this).val().match(regexp)){
     $(this).val( $(this).val().replace(regexp,'') );
   }
 });

 $(".address").on('input', function(event) {
  var regexp = /[^a-zA-Z0-9 /,]/g;
   if($(this).val().match(regexp)){
     $(this).val( $(this).val().replace(regexp,'') );
   }
 });

 $(".textonly").on('input', function(event) {
  var regexp = /[^a-zA-Z]/g;
   if($(this).val().match(regexp)){
     $(this).val( $(this).val().replace(regexp,'') );
   }
 });
 
 $(".textnumber").on('input', function(event) {
  var regexp = /[^a-zA-Z0-9]/g;
   if($(this).val().match(regexp)){
     $(this).val( $(this).val().replace(regexp,'') );
   }
 });
 
 $(".numberonly").on('input', function(event) {
  var regexp = /[^0-9]/g;
   if($(this).val().match(regexp)){
     $(this).val( $(this).val().replace(regexp,'') );
   }
 });

 $(".onlytextspace").on('input', function(event) {
   var regexp = /[^a-zA-Z\s]+$/g;  
   if($(this).val().match(regexp)){
     $(this).val( $(this).val().replace(regexp,'') );
   }
 }); 

 $(".onlydottextspace").on('input', function(event) {
     //var regexp = /^([\s\.]?[a-zA-Z0-9]+)+$/;
  var regexp = /[^,/0-9a-zA-Z\s\.]+$/g;  
   if($(this).val().match(regexp)){
     $(this).val( $(this).val().replace(regexp,'') );
   }
 });



$(document).ready(function(){
 
 $('#class_id').change(function(){
 var classId = $('#class_id').val();

 $.ajax({      
   url: base_url+base_path+"/get-subject-list",
   type: "post",
   data: { classId : classId },
   dataType: "json",
   
  success: function(data){
     $("#subject_id").empty();
     $("#subject_id").append('<option>Select Subject</option>');
     $.each(data,function(key,value){
     $("#subject_id").append('<option value="'+key+'">'+value+'</option>');
    });
   }
  });
 });
     
});





$('#edudist_name').click(function(){
    
   var edudistId = $('#edudist_name').val();  
   var edudist=[];
   
  $.ajax({      
    url: base_url+base_path+"/check-rev-school",
    type: "post",
    data: { edudistId : edudistId },
    dataType: "json",
    
   success: function(data){
      $("#camp_id").empty();
      $("#camp_id").append('<option>Select</option>');
      $.each(data,function(key,value){
      $("#camp_id").append('<option value="'+key+'">'+value+'</option>');
       edudist.push(key);
       });
        $("#edudist_name").append('<option value="'+edudist.join()+'"> ALL </option>');
     }
   });
 });



       $("#date1").datepicker({
            dateFormat: "dd-mm-yy",
            maxDate : 0, 
            onSelect: function (date) {
                var dt1 = $('#date1').datepicker('getDate');
                var dt2 = $('#date2').datepicker('getDate');
                
                $('#date2').datepicker('option', 'minDate', dt1);
            }
        });
        $('#date2').datepicker({
            dateFormat: "dd-mm-yy",
            maxDate : 0, 
            minDate: $('#date1').datepicker('getDate'),
            onClose: function () {
                var dt1 = $('#date1').datepicker('getDate');
                var dt2 = $('#date2').datepicker('getDate');
                //check to prevent a user from entering a date below date of dt1
                if (dt2 <= dt1) {
                    var minDate = $('#date2').datepicker('option', 'minDate');
                    $('#date2').datepicker('setDate', minDate);
                }
            }
          });      
 });

Our Feature Post

There is a tree between houses of A and B If the tree leans on As House

    There is a tree between houses of A and B. If the tree There is a tree between houses of A and B. If the tree leans on A’s House, the t...

Our Popular Post