Saturday, August 3, 2019

Present Perfect Continuous Tense

This tense express an action that started in past and continued to present or recently stopped. It is used to state an ongoing action that has started at a point in the past. A time reference is also used in the sentence to show that when the action started in past or for how long the action continued.

The specific words 'since' and 'for' are used in a sentence to show the time of action. The word 'Since' is used if the exact starting time of action is known or intended to be reflected in the sentence. The word 'for' is used to express the amount of time for which the action was continued.

Structure of the Sentence.

Main Verb: Present Participle (Base form + ing) E.g : going, eating
Auxiliary verb: Have been, Has been

Note :  If the subject of "she, he, it, or a singular noun", the auxiliary verb "has been" is used. If the subject of the sentence is "they, you, or a plural noun", the auxiliary verb "have been" is used.

Positive Sentences:

  • Subject + Auxiliary verb + Main verb + Time-reference
  • Subject + Have been / Has been + Present Participle (verb + ing) + Time-reference
Examples : 
  1.  He has been living in New York since 1993.
  2. She has been working in an organization since 2005.
  3. He has been studying this book for three months. 
  4. I have been watching the movie since 3 O'clock.
  5. They have been teaching in this school for three years.
Negative Sentences:

  • Subject + Auxiliary verb + Main verb + Time-reference
  • Subject + Have not been / Has not been + Present Participle (verb + ing) + Time-reference
Examples:
  1. He has not been working in factor since 2007.
  2. She has not been studying her books for five days.
  3. I have not been meeting him since 2012.
  4. They have not been completing their work since Monday.
  5. Kids have been not been playing games for five hours.
Interrogative Sentences:
  • Has / Have + Subject + Been + Present Participle (verb + ing) + Time-reference
Examples: 
  1. Have you been going to your college since 2013?
  2. Has he been working as a teacher for three years?
  3. Has she been writing the report since 7th August 2011?
  4. Have they been making a noise for one hour?
  5. Have I been wasting my time for three days?

Mongoose


What is Mongoose?

  • Mongoose is an object modelling package for Node that essentially works like an ORM (Object-relational mapping ) that you would see in other languages.
  • Mongoose allows us to have access to the MongoDB commands for CRUD simply and easily.

Mongoose Installation

  • npm install mongoose --save
What is Schema?
  • "Mongoose Schema will create a mongodb collection and defines the shape of the documents within that collection".
  • If we want to create a mongodb collection in a structured manner similar to SQL tables then we can do that using mongoose Schema.
  • In the schema creation we will specify the details of fields like field name, its type, default value if need, index concept if need, constraint concept if need.


What is the Model?
  • Schemas define a structure we will apply that Schema part to a model, means "Models are the constructors compiled from our schema definitions".
  • Instances of these models represent documents which can be saved and retrieved from our database. All document creation and retrieval from the database is handled by these models.

Key Methods and Properties of Mongoose                    

Connect() :- Opens the default mongoose connection.
CreateConnection() :-Will creates a connection instance and its work is similar to connect()
Schema():-The Mongoose Schema constructor
Model():-The Mongoose Model constructor
Document() :-The Mongoose Document constructor.
Disconnect():- Disconnects all connections.

Mongoose Connection

Open(): Opens the connection to MongoDB.
OpenSet(): Opens the connection to a replica set.

close() : Closes the connection, it doesn’t throw any error even the connection is not opened or already closed.

readyState : It is the property of connection which holds the state of the connection.

Mongoose Schema

  • constructor
syntax:-  Schema(definition, [options])
Example

  • add ( )
syntax:-    add(obj,prefix)
Example

  • get ( )
syntax:-  get(optionkey)
Example
  • set ( )
syntax:-   set(key, [value]) 
Example

  • index ( )
syntax:-  index(fields, [options], [options.expires=null])
Example 

  • method ( )
syntax:-  method(methodname, function code)
Example 

  • static ( )
syntax:-  static(method name,function def);
Example

  • pre ( )
  • post ( )
Mongoose model

  • Constructor Model( )
syntax:-   Model(doc)
  • save ( )
syntax:-  save([options], [options.safe], [options.validateBeforeSave], [fn])
Example
  • find ()
Syntax:- find(conditions, [projection], [options], [callback])
  • update ( )
Syntax:-  update(conditions, doc, [options], [callback])
Example 
  • remove ( )
Syntax:-  remove(conditions, [callback])
Example 













































Sunday, July 28, 2019

ER Diagram



  • 1976 proposed by Peter Chen
  • An ER diagram is widely used in database design
    • Represent the conceptual level of a database system
    • Describe things and their relationships at a high level
Basic Concepts
  • Entity set – an abstraction of similar things, 
    • E.g:- cars, students
  • An entity set contains many entities
    • Entities are represented by means of rectangles. 
    • Rectangles are named with the entity set they represent.
    • E.g:- Teacher, Student, Project.


  • Attributes: Common properties of the entities in an entity sets. Attributes are represented by means of ellipses. Every ellipse represents one attribute and is directly connected to its entity.


Attribute

  • Composite VS Simple Attributes
  • Single valued VS Multivalued Attributes
  • Stored VS Derived Attributes
  • Complex Attributes 

Relationship – specify the relations among entities from two or more entity sets
A relationship where two entities are participating is called a binary relationship. Cardinality is the number of instance of an entity from a relation that can be associated with the relation.

 One-to-one 

One-to-many

many-to-one

many-to-many


Keys

Key is an attribute or collection of attributes that uniquely identifies an entity among the entity set.

1.    Super Key − A set of attributes (one or more) that collectively identifies an entity in an entity set.
2.    Candidate Key − A minimal super key is called a candidate key. An entity set may have more than one candidate key.
3.    Primary Key − A primary key is one of the candidate keys chosen by the database designer to uniquely identify the entity set.













             








    Thursday, July 18, 2019

    Present Perfect Continuous Tense

    This tense express an action that started in past and continued to present or recently stopped. It is used to state an ongoing action that has started at a point in the past. A time-reference is also used in the sentence to show that when the action started in past or for how long the action continued.

    The specific words 'since' and 'for' are used in sentence to show the time of action. The word 'since' is used if the exact starting time of action is known or intended to be reflected in the sentence. The word 'for' is used to express the amount of time for which the action was continued.

    Structure of Sentence.

    Tuesday, July 16, 2019

    Node.js MongoDB



    • Node.js can be used in database applications.
    • One of the most popular NoSQL databases is MongoDB. 
     Creating a Database
    • To create a database in MongoDB, start by creating a MongoClient object, then specify a connection URL with the correct IP address and the name of the database you want to create.

    • MongoDB will create the database if it does not exist, and make a connection to it.
    Example :
     create a database called "my_data"

                     var MongoClient = require('mongodb').MongoClient;
                     var url = "mongodb://localhost:27017/my_data";

                     MongoClient.connect(url, function(err, db) {
                     if (err) throw err;
                     console.log("Database created!");
                     db.close();
                     });


    Creating a Collection
    • To create a collection in MongoDB, use the createCollection( ) method
    Example :
           Create a collection called "customers"

                       var MongoClient = require('mongodb').MongoClient;
                       var url = "mongodb://localhost:27017/";

                       MongoClient.connect(url, function(err, db) {
                             if (err) throw err;
                             var dbo = db.db("my_data");
                             dbo.createCollection("customers", function(err, res) {
                                 if (err) throw err;
                                 console.log("Collection created!");
                                 db.close();
                            });
                      });


    Insert into Collection 
    • To insert a record, or document as it is called in MongoDB, into a collection, we use the insertOne( ) method.
    • A document in MongoDB is the same as a record in MySQL
    • The first parameter of the insertOne( ) a method is an object containing the name(s) and value(s) of each field in the document you want to insert.
    • It also takes a callback function where you can work with any errors or the result of the insertion:
    Example :
         Insert a document in the "customers" collection:
                  var MongoClient = require('mongodb').MongoClient;
          var url = "mongodb://localhost:27017/";

          MongoClient.connect(url, function(err, db) {
             if (err) throw err;
             var dbo = db.db("my_data");
             var myobj = { name: "Company Inc", address: "Highway 37" };
             dbo.collection("customers").insertOne(myobj, function(err, res) {
                if (err) throw err;
                console.log("1 document inserted");
                db.close();
             });
         });


    Insert Multiple Documents

    • To insert multiple documents into a collection in MongoDB, we use the insertMany( ) method.
    • The first parameter of the insertMany( ) a method is an array of objects, containing the data you want to insert.
    • It also takes a callback function where you can work with any errors or the result of the insertion:
    Example :
        Insert multiple documents in the "customers" collection:
        var MongoClient = require('mongodb').MongoClient;
        var url = "mongodb://localhost:27017/";

        MongoClient.connect(url, function(err, db) {
           if (err) throw err;
           var dbo = db.db("my_data");
           var myobj = [
             { name: 'John', address: 'Highway 71'},
             { name: 'Peter', address: 'Lowstreet 4'},
             { name: 'Amy', address: 'Apple st 652'},
             { name: 'Hannah', address: 'Mountain 21'},
             { name: 'Michael', address: 'Valley 345'},
             { name: 'Sandy', address: 'Ocean blvd 2'},
             { name: 'Betty', address: 'Green Grass 1'}
           ];
           dbo.collection("customers").insertMany(myobj, function(err, res) {
             if (err) throw err;
             console.log("Number of documents inserted: " +                       res.insertedCount);
             db.close();
           });
         });


    Node.js MongoDB Find
    •  In MongoDB we use the find and findOne methods to find data in a collection.
    •  Just like the SELECT statement is used to find data in a table in a MySQL database.
    Find One
    • To select data from a collection in MongoDB, we can use the findOne() method.

    • The findOne() method returns the first occurrence in the selection.

    • The first parameter of the findOne() method is a query object. In this example we use an empty query object, which selects all documents in a collection (but returns only the first document).
    Example :
     Find the first document in the customers collection:

    var MongoClient = require('mongodb').MongoClient;
    var url = "mongodb://localhost:27017/";

    MongoClient.connect(url, function(err, db) {
      if (err) throw err;
      var dbo = db.db("mydb");
      dbo.collection("customers").findOne({}, function(err, result) {
        if (err) throw err;
        console.log(result.name);
        db.close();
      });
    });


    Find All
                








    Present Perfect Tense

    Present Perfect Tense is used to express an action that occurred or completed at some point in past. This tense expresses an idea of completion or occurrence of an action in past without giving an idea about the exact time of its occurrence. Though, the time of the action is not exactly known, this tense is mostly used to refer to actions completed in the recent past (not a very long time ago).

    • Positive Sentences
                Subject + Auxiliary verb + Main verb + Object
                Subject + Have/Has + Past Participle (3rd form of verb) + An Object

    Examples :
    1. The guests have arrived.
    2. I have eaten my meal.
    3. You have done a nice job.
    4. He has received my letter.
    5. She has given me her books.
    6. They have helped us.
    • Negative Sentences
                 Subject + Auxiliary verb + Main verb + Object
                 Subject + Have/Has + NOT + Past Paticiple + Object
    Examples :
    1. You have not completed you work.
    2. She has not applied for a job.
    3. He has not brought the table.
    4. They have not enjoyed the party.
    5. They have not called us.
    6. He has not started a business.
    7. She has not come.
    • Interrogative Sentences
             Auxiliary verb + Subject + Main verb + Object
             Have/Has + Subject + Past Participle + Object
    Examples : 

    1. Have you prepared yourself for the exam?
    2. Has she brought her camera?
    3. Has he finished his work?
    4. Have they played a game?
    5. Have the kids eaten their food?
    6. Have I send you a mail?

    Sunday, July 7, 2019

    Present Continous Tense

    What Is Present Continuous Tense?

    Present continuous tense, otherwise known as the present progressive tense, is formed when the present tense of the 'to be' verb is connected with a present participle. A present participle is a verb that ends in '-ing'. The present continuous tense allows the speaker to talk about things that are and that are not happening now, temporarily, repeatedly, and in the near future. In this lesson, we will go over the uses of present continuous tense and look at examples to help you fully understand how to properly use this tense in a sentence.

    Present Continuous Tense Uses

    The present continuous tense cannot be used with non-continuous verbs or mixed verbs. A non-continuous verb is a verb that cannot be physically seen. For example, the verbs 'to love', 'to own', and 'to need' are examples of non-continuous verbs. A mixed verb is a verb that can have multiple meanings and behave like a normal or non-continuous verb. The verbs 'to have' and 'to miss' are examples of mixed verbs.
    Let's gain an understanding of the other rules for using present continuous tense by looking at a few examples, starting with talking about the present. The present continuous tense can be used to talk about the present when the speaker is referring to something that is happening in that moment or something that occurs before or after a certain time.
    If something is or is not happening at the moment, the speaker might say:
    • I'm running to the store; I'll be home later.
    • The baby is sleeping.
    • I am not eating doughnuts for breakfast.
    If something is happening before or after a certain time, the speaker might say:
    • At two in the afternoon, we are eating lunch.
    • When you come home, dinner is cooking in the oven.

    Express

    What is Express? Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develo...