June 24, 2021

React JS Interview Questions and topics

 To evaluate a candidate, recruiters generally asks certain questions so that they can know how much the candidate has hands-on experience and how much is his/her technical capabilities. Below are some of the questions:

  • What is Virtual DOM?
  • Explain how React Routing works?
  • What are the ways to debug React JS application?
  • What are the libraries needed for unit testing. Write a sample unit test.
  • How to configure application so that whenever an user commits code, it first checks the code alignments and other lint issues and fix them automatically.
  • How to configure application so that whenever user pushes code to source control, it first run all unit test cases and on success only it pushes the code to the repo
  • What is Responsize web design?
  • How does Exception Handling works,
  • What type of configuration needed to deploy an react application on mulitple environments.
  • How to maintain configuration data like API URLs, API Keys etc based on different environments in application.
  • Difference between const and let. Write an example.
  • Difference between == and ===, write an example.
  • what is use of pre commit and post commit in package.json?
  • Difference between ES6 functions like filter and find.
  • How to configure redux in the application.
  • How to access lifecycle methods in functional components.
  • Which lifecycle methods we can access using useEffect hook.
  • How and where we can use Spread Operator?
  • What is the use of JWT token and how does it works.

June 18, 2021

How to query like joins on 2 collections in mongodb using aggregate keyword

To query like JOINS between 2 collections in mongodb, we need to use $aggregate.

Lets see the example:
 
I have 2 collections, one is Employee and another one is Department.
 Employee Collection  
           {    
             "_id" : 1,    
             "name" : {    
                "first" : "Abhi",    
                "last" : "Dev"    
             },    
             "departmentId" : 2
            },    
            {    
             "_id" : 2,    
             "name" : {    
                "first" : "Abc",    
                "last" : "Agrawal"    
             },    
              "departmentId" : 1 
            },    
            {    
             "_id" : 3,    
             "name" : {    
                "first" : "Dhruv",    
                "last" : "Agrawal"    
             },    
             "departmentId" : 1,    
            }  
           }   

Department Collection  
           {    
             "_id" : 1,    
             "name" : "finance" 
            },    
            {    
             "_id" : 2,    
             "name" : "hr" 
            }
           } 

Now I need to fetch employee details for id 2 along with employee's department name. 

The query would be:

db.employee
    .aggregate([
      { $match: { _id: 2 } },
      {
        $lookup: {
          localField: 'departmentId',
          from: 'department',
          foreignField: '_id',
          as: 'departmentName',
        },
      },
      { $unwind: '$departmentName' }
]).toArray()

The output would be:

	{    
         "_id" : 2,    
         "name" : {    
         	"first" : "Abc",    
         	"last" : "Agrawal"    
         },
         "departmentName": {
            "name": "finance"
         }

Hope it helps.