Tuesday, 1 December 2015

MongoDB Interview Questions and Answer on Database

MongoDB Interview Questions and Answer on Database

Question: What is Relationships in MongoDb?
Relationships in MongoDb represent how various documents are related to each other.
For Example:
There are various documents like user, address, payment details etc.
Connection between these documents know as Relationships.


Question: What is Two type Relationships?
  1. Modeling Embedded Relationships
  2. Modeling Referenced Relationships



Question: What is Modeling Embedded Relationships?
In this Approach, we embed the one document into other.
For Example:
{
   "_id":ObjectId("521234cd85242f436000007"),
   "contact": "987685555555",
   "dob": "01-01-1992",
   "name": "User1",
   "address": [
      {         
         "pincode": 160011,
         "city": "Mohali",
       
      },
      {
         "pincode": 140301,
         "city": "Mohali",
      }
   ]
}

We have added the both address in in user document.


Question: Modeling Referenced Relationships?
In this approach, We add the referenceId instead of whole document, thats why know as Referenced Relationships.
For Eample:
{
   "_id":ObjectId("521234cd85242f436000007"),
   "contact": "987685555555",
   "dob": "01-01-1992",
   "name": "User1",
   "address": [
      ObjectId("521234ce85242f436000001"),
      ObjectId("521234ce85242f436000002")
   ]
}


Above is also know as Manual References because we put the RefereceId static.


Question: What is different between "Manual References" and "DBRefs References"?
Manual References
where you save the _id field of one document in another document as a reference know as Manual References.
Just see the above question for Example.

DBRefs References
References the one document with another using the value of first document's _id field, collection name, and database name.



Question: Explain the DBRefs References in detail?
There are three fields in DBRefs:
$ref: This field specifies the collection of the referenced document.
$id: This field specifies the _id field of the referenced document.
$db: Database name where referenced document lies. This is Optional.
{
   "_id":ObjectId("521234cd85242f436000007"),
   "address": {
   "$ref": "address_home",
   "$id": ObjectId("521234cd85242f436000007"),
   "$db": "webtechnology"},
   "contact": "987685555555",
   "dob": "01-01-1991",
   "name": "web-tech"
} 



Question: What is a Covered Query?
Covered query is a query in which all the "fields of Query" and "fields returned in the query" are same index.
For Example:
{
   "_id":ObjectId("521234cd85242f436000007"),
   "address": {
   "$ref": "address_home",
   "$id": ObjectId("521234cd85242f436000007"),
   "$db": "webtechnology"},
   "contact": "987685555555",
   "dob": "01-01-1991",
   "name": "web-tech"
} 

Add "Index"
db.users.ensureIndex({name:1,usercontact:1})


If we are using below:
db.users.find({name:"web-tech"},{usercontact:"987685555555",_id:0})

This is best example for Covered Query.




Question: How to Analyzing the queries in MongoDB?
$explain: The $explain operator provides information on the query, indexes and other statistics. For analyse the use just add .explain() at the end of query.
db.users.find({name:"web-tech"}).explain()


Question: What is use of $hint operator?
$hint: operator is used to forces the query optimizer to use the specified index to run a query.
It is useful when you want to test performance of a query with different indexes with applying the index in real.
db.users.find({name:"web-tech"}).hint({dob:"01-01-2015"}).explain()



Question: Does MongoDb provides atomic transactions?
Yes, but provides only for single document.
In this way, Either it update all fields or none.
db.myproducts.findAndModify({ 
   query:{_id:2,product_available:{$gt:0}}, 
   update:{ 
      $inc:{product_available:-1}, 
      $push:{product_bought_by:{customer:"webtech",date:"19-Jan-2014"}} 
   }    
})



Question: How to add index on document?
db.users.ensureIndex({"dob":1})




Question: How to add index on sub document?
db.users.ensureIndex({"address.city":1,"address.state":1})




Monday, 30 November 2015

AngularJS Interview Questions and Answers for Experienced

AngularJS Interview Questions and Answers for Experienced



Question: What is AngularJS?
It is javasScript framework which is written in javascript. It is Best for Single Page Applications. It extend the html with new attributes which makes it more useful for UI Developer.


Question: In which language, AngularJS is written?
javaScript


Question: When First AngularJS was released?
2009

Question: When latest AngularJS was released?
November 24, 2017


Question: What is latest version of AngularJS?
1.6.7


Question: Who created AngularJS?
Misko Hevery started to work on AngularJS in 2009. He was employee of Google.
Question: Is it opensource?
Yes, It is free to use.



Question: Explain what are the key features of Angular.js?
  1. Scope
  2. Controller
  3. Model
  4. View
  5. Services
  6. Data Binding
  7. Directives
  8. Filters
  9. Testable



Question: From where we can download the AngularJS File?
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>



Question: What is controller in AngularJS?
Controller is constructor function in Angular Controller.
When a Controller is attached to the DOM with use the ng-controller, Angular will instantiate a new Controller object using constructor function.



Question: Explain what are directives?
Directives are used to add new attributes of HTML.



Question: What are the different types of Directive?
Different types of directives are
  1. Element directives
  2. Attribute directives
  3. CSS class directives
  4. Comment directives



Question: Explain what is injector?
An injector is a service locator, used to retrieve object instances.



Question: Explain what are factory method in angularJs?
Factory method are used to create the directive. It is invoked only once, when compiler matches the directive for the first time.



Question: Does Angular use the jQuery library?
Ans. Yes, Angular can use jQuery if you have included the jQuery library.
IF Not, Angular falls back to its own implementation of the subset of jQuery that we call jQLite.



Question: What is ng-app, ng-init and ng-model?
ng-app - To initialize the Angular Application.
ng-init - To initialize the Angular Application data.
ng-model - To bind the html tags (input, select, textarea) to Angular Application Data.



Question: What is Data Binding in Angular JS?
It is synchronization of data between the model(Angular Application variable) and view components (display with {{}}).



Question: Give an Example of Data-Binding in AngularJS?
<div ng-app="" ng-init="quantity=10;cost=5">
<b>Total Cost: {{ quantity * cost }}</b>
</div>


Question: What is Looping in AngularJs and Give an Example?
It is used to display the data in loop same as foreach in PHP
Example:
<div data-ng-app="" data-ng-init="names=['Web','Technology','Experts','Notes']">
<b>Loop Example:</b>
  <br />
<ul>
<li data-ng-repeat="x in names">
      {{ x }}
    </li>
</ul>
</div>

Question: How to Write Expression in AngularJS?
<div ng-app="">
<b>Expression: {{ 15 + 55 }}</b>
</div>



Question: How to initiate variable in AngularJS?
<div ng-app="" ng-init="quantity=10;cost=5">
<b>Total Cost: {{ quantity * cost }}</b>
</div>


OR

<div ng-app="" ng-init="quantity=1;cost=5">
<b>Total Cost: <span ng-bind="quantity * cost"></span></b>
</div>



Question: Example of AngularJS Strings?
<div ng-app="" ng-init="Str1='Web';Str2='Technology'">
Full String is : <b>{{ Str1 + " " + Str2 }}</b>
</div>




Question: Example of AngularJS Object?
<div ng-app="" ng-init="myobj={Str1:'Web',Str2:'Technology'}">
String Display: <b>{{ myobj.Str2 }}</b></div>



Question: What is Angular Controllers & give an Example?
Controller is constructor function in Angular Controller.
When a Controller is attached to the DOM with use the ng-controller, Angular will instantiate a new Controller object using constructor function.
Example:
<div ng-app="" ng-controller="StrControllerExample">
String 1: <input ng-model="str1" type="text" /><br />
String 2: <input ng-model="str2" type="text" /><br />
Full String <b> {{fullString()}}</b>
</div>
<script>
function StrControllerExample($scope) {
    $scope.str1 = "Web",
    $scope.str2 = "Technology",
    $scope.fullString = function() {
        return $scope.str1+ " " + $scope.str2;
    }
}
</script>




Question: What is Dependency Injection?
Dependency Injection (DI) is a software design pattern that deals with how components get deal of their dependencies.