HTML5 – Getting Started Guide

This video tutorial teaches how to start with HTML5.
Some basic changes that you need to know before starting to learn HTML5.

Technologies involved to learn HTML5:
Javascript API.
CSS3.
HTML5.

html5-features

Some of the things we’ll be learning throughout this course:
New Elements
New Attributes
CSS3 Selectors
Rounded Corners
Shadow Effects
Video and Audio
2D/3D Graphics
Local Storage
offline caching
web workers
Drag and Drop
Geolocation
Working with Google Maps API.
Forms
Sockets
Canvas ..etc

HTML5 File
index.html

1
2
3
4
5
6
7
8
9
10
< !doctype html>
<html>
 <head>
  <title>HTML5 Tutorials: from Technotip</title>
  <meta charset="UTF-8"/>
 </head>
 <body>
  <p>This is a video tutorial sponsored by or produced by Technotip.com</p>
 </body>
</html>

Doctype: no more Googling or copy pasting or relying on your fancy text editors to get the clumsy looking doctypes. With HTML5, the doctype has been simplified and is easy to remember.

Doctypes for HTML6, HTML7 ?
The doctype will stay the same for HTML5, HTML6, HTML7, HTML8, HTML9, HTML10, HTML11, HTML12 etc :-) This is a promise from W3C.

Previous HTML versions(like xHTML, HTML4, HTML4.0.1 etc) depended on SGML, but HTML5 and onwards it doesn’t depend on SGML. When the browser parses the first line(i.e., the doctype of HTML5), it’ll execute in HTML5 standards mode.

By using a doctype the browser is able to be more precise in the way it interprets and renders your pages. If you don’t specify any doctype, it still works, but it may cause the browser to render things wrongly. And it may take more time for the browser to fail gracefully, after trying to figureout all possible ways to parse the tags and to try its best to present your web pages properly.

Meta tag
It has also been simplified and now, only character set information is enough.

CSS – Cascading Stylesheet

1
 <link rel="stylesheet" href="style.css"/>

In HTML5 there is no need to write the type attribute with link tag.
Because CSS has been declared as the standard and default style for HTML5.

JavaScript

1
 <script src="myScript.js"></script>

In HTML5 there is no need to write the type attribute with script tag.
Because JavaScript has been declared as the standard and default scripting language for HTML5.

Embeded JavaScript

1
2
3
 <script>
var name = "Technotip.com";
 </script>

If you’re writing embeded javascript, then you can simply start with a opening script tag and a closing script tag. Here too, you need not specify the type attribute.

Introduction To HTML5


[youtube https://www.youtube.com/watch?v=cBW5PUiAG7s]

YouTube Link: https://www.youtube.com/watch?v=cBW5PUiAG7s [Watch the Video In Full Screen.]



Upgrade your web pages to HTML5
To upgrade your web pages to HTML5 standards, simply make these small changes:
1. doctype.
2. remove type attribute from link and script tags.
3. remove and if needed replace deprecated tags(will discuss in coming video tutorials) from your website.

Use validator.w3.org tool to check your webpage.

Comparison Operators: MongoDB

In this video tutorial we shall illustrate the use of comparison operators in MongoDB.

Comparison Operators
$all
$in
$nin – not in
$ne – not equal to
$gt – greater than
$gte – greater than or equal to
$lt – less than
$lte – less than or equal to

red-apple-green-apple-comparison

JavaScript file
load.js – in path: C:/test/load.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
db.person.insert({
name   : 'Satish',
age    : 25,
skills : ['nodejs', 'mongoDB', 'HTML5']
});
 
db.person.insert({
name   : 'Kiran',
age    : 27,
skills : ['PHP', 'mySQL', 'HTML5']
});
 
db.person.insert({
name   : 'Sunitha',
age    : 24,
skills : ['html', 'ASP']
});
 
db.person.insert({
name   : 'Jyothi',
age    : 23,
skills : ['html', 'ASP']
});
 
db.person.insert({
name   : 'Varsha',
age    : 30,
skills : ['.NET', 'Java']
});
 
db.person.insert({
name   : 'Amogh',
age    : 29,
skills : ['C#', 'ASP']
});

This JavaScript file contains some simple data, to be inserted into MongoDB server.
It contains, persons name, age and skills(in array form)
person is the collection name, we’re creating.

From our previous day video tutorial we already know, how to, Load Data From External JavaScript File: MongoDB.

load script to new database

1
2
3
4
5
6
7
8
9
C:\mongodb>cd bin
 
C:\mongodb\bin>mongo 127.0.0.1/satish C:/temp/load.js
MongoDB shell version: 2.4.3
connecting to: 127.0.0.1/satish
 
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test

Once these data/documents are loaded into new database, we start operating on this data using comparison operator.

Documents In person Collection

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
> db.person.find().forEach(printjson)
{
        "_id" : ObjectId("518c76ba05ea2a1d2b3b33a0"),
        "name" : "Satish",
        "age" : 25,
        "skills" : [
                "nodejs",
                "mongoDB",
                "HTML5"
        ]
}
{
        "_id" : ObjectId("518c76ba05ea2a1d2b3b33a1"),
        "name" : "Kiran",
        "age" : 27,
        "skills" : [
                "PHP",
                "mySQL",
                "HTML5"
        ]
}
{
        "_id" : ObjectId("518c76ba05ea2a1d2b3b33a2"),
        "name" : "Sunitha",
        "age" : 24,
        "skills" : [
                "html",
                "ASP"
        ]
}
{
        "_id" : ObjectId("518c76ba05ea2a1d2b3b33a3"),
        "name" : "Jyothi",
        "age" : 23,
        "skills" : [
                "html",
                "ASP"
        ]
}
{
        "_id" : ObjectId("518c76ba05ea2a1d2b3b33a4"),
        "name" : "Varsha",
        "age" : 30,
        "skills" : [
                ".NET",
                "Java"
        ]
}
{
        "_id" : ObjectId("518c76ba05ea2a1d2b3b33a5"),
        "name" : "Amogh",
        "age" : 29,
        "skills" : [
                "C#",
                "ASP"
        ]
}

Comparison Operators: MongoDB


[youtube https://www.youtube.com/watch?v=937PSHo7F00]

YouTube Link: https://www.youtube.com/watch?v=937PSHo7F00 [Watch the Video In Full Screen.]



Switch to new database, ‘satish’

1
2
3
4
5
6
7
> show dbs
admin   0.203125GB
company 0.203125GB
local   0.078125GB
satish  0.203125GB
> use satish
switched to db satish

$all operator

1
2
3
4
> db.person.find({skills: { $all: ['html', 'css'] }}, {name: 1, _id: 0});
> db.person.find({skills: { $all: ['html', 'ASP'] }}, {name: 1, _id: 0});
{ "name" : "Sunitha" }
{ "name" : "Jyothi" }

Matches arrays that contain all elements specified in the query.

$in operator

1
2
3
4
5
6
> db.person.find({skills: { $in: ['html', 'css'] }}, {name: 1, _id: 0});
{ "name" : "Sunitha" }
{ "name" : "Jyothi" }
> db.person.find({skills: { $in: ['java', 'css'] }}, {name: 1, _id: 0});
> db.person.find({skills: { $in: ['Java', 'css'] }}, {name: 1, _id: 0});
{ "name" : "Varsha" }

Matches any of the values that exist in an array specified in the query.

$nin operator: not in

1
2
3
4
5
6
7
8
9
> db.person.find({skills: { $nin: ['Java', 'css'] }}, {name: 1, _id: 0});
{ "name" : "Satish" }
{ "name" : "Kiran" }
{ "name" : "Sunitha" }
{ "name" : "Jyothi" }
{ "name" : "Amogh" }
> db.person.find({skills: { $nin: ['Java', 'ASP'] }}, {name: 1, _id: 0});
{ "name" : "Satish" }
{ "name" : "Kiran" }

Matches values that do not exist in an array specified to the query.

$gt operator

1
2
3
4
> db.person.find({age: { $gt: 25 }}, {name: 1, _id: 0});
{ "name" : "Kiran" }
{ "name" : "Varsha" }
{ "name" : "Amogh" }

Matches values that are greater than the value specified in the query.

$gte operator

1
2
3
4
5
> db.person.find({age: { $gte: 25 }}, {name: 1, _id: 0});
{ "name" : "Satish" }
{ "name" : "Kiran" }
{ "name" : "Varsha" }
{ "name" : "Amogh" }

Matches values that are equal to or greater than the value specified in the query.

Combining multiple operators: $gt, $gte and $lt operator

1
2
3
4
5
6
7
8
> db.person.find({age: { $gte: 25, $lt: 29 }}, {name: 1, _id: 0});
{ "name" : "Satish" }
{ "name" : "Kiran" }
> db.person.find({age: { $gt: 25, $lt: 29 }}, {name: 1, _id: 0});
{ "name" : "Kiran" }
> db.person.find({age: { $gt: 25, $lte: 29 }}, {name: 1, _id: 0});
{ "name" : "Kiran" }
{ "name" : "Amogh" }

$lt – less than – Matches vales that are less than the value specified in the query.
$lte – less than or equal to – Matches values that are less than or equal to the value specified in the query.

$ne operator

1
2
3
4
5
6
> db.person.find({age: {$ne: 25}}, {name: 1, _id: 0});
{ "name" : "Kiran" }
{ "name" : "Sunitha" }
{ "name" : "Jyothi" }
{ "name" : "Varsha" }
{ "name" : "Amogh" }

Matches all values that are not equal to the value specified in the query.

Note:
Operators are useful when we do not know the exact value to be extracted or to fetch a range of values.
All mongoDB operators begin with $ sign.

Load Data From External JavaScript File: MongoDB

This video tutorial illustrates loading data to mongoDB server from an external JavaScript file ( Writing script for MongoDB shall )

Here, we write a simple JavaScript file and using command prompt we load the contents of JavaScript file into new Database.

import-data

JavaScript file
load.js – in path: C:/temp/load.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
db.person.insert({
name:'Satish',
age:25,
skills:['nodejs', 'mongoDB', 'HTML5']
});
 
db.person.insert({
name:'Kiran',
age:27,
skills:['PHP', 'mySQL', 'HTML5']
});
 
db.person.insert({
name:'Sunitha',
age:24,
skills:['html', 'ASP']
});

Here we’re inserting some data/record/documents into the collection person.

Database’s Before running the script

1
2
3
4
5
6
7
8
9
10
11
12
13
C:\>cd mongodb
 
C:\mongodb>cd bin
 
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
> show dbs
admin   0.203125GB
company 0.203125GB
local   0.078125GB
> exit
bye

Before running the script, we have only 3 databases.

Running the script

1
2
3
C:\mongodb\bin>mongo 127.0.0.1/satish C:/temp/load.js
MongoDB shell version: 2.4.3
connecting to: 127.0.0.1/satish

Here, mongo is the JavaScript shall.
127.0.0.1 is nothing but our localhost.
satish is the new database we are creating.
C:/temp/load.js is the path of load.js file.
We’re loading the contents of load.js file into new database satish.

Database’s After running the script

1
2
3
4
5
6
7
8
9
10
11
12
13
C:\mongodb\bin>mongo
MongoDB shell version: 2.4.3
connecting to: test
> show dbs
admin   0.203125GB
company 0.203125GB
local   0.078125GB
satish  0.203125GB
> use satish
switched to db satish
> show collections
person
system.indexes

New database satish has been added and it has person collection, which we loaded from the JavaScript file.

Documents/records In person collection

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
> db.person.find().forEach(printjson)
{
        "_id" : ObjectId("518b62443cbad352108c321b"),
        "name" : "Satish",
        "age" : 25,
        "skills" : [
                "nodejs",
                "mongoDB",
                "HTML5"
        ]
}
{
        "_id" : ObjectId("518b62443cbad352108c321c"),
        "name" : "Kiran",
        "age" : 27,
        "skills" : [
                "PHP",
                "mySQL",
                "HTML5"
        ]
}
{
        "_id" : ObjectId("518b62443cbad352108c321d"),
        "name" : "Sunitha",
        "age" : 24,
        "skills" : [
                "html",
                "ASP"
        ]
}

Using find() method we display all its contents.

This way we could load application data from an external JavaScript file.

Writing script for MongoDB shall


[youtube https://www.youtube.com/watch?v=ygK2zE1-k0w]

YouTube Link: https://www.youtube.com/watch?v=ygK2zE1-k0w [Watch the Video In Full Screen.]



Note:
This method will be handy while migrating our application from one mongoDB server to another mongoDB server.
There is import/export options in mongoDB, but this method is also helpful if we have some custom data to be inserted. nontheless a useful tool to have.

SELECT Columns/Fields: MongoDB

In this video tutorial we shall see selecting of key: value in MongoDB.

In RDBMSs like MySQL, we do the same using SELECT statement.
In MongoDB, we use findOne() and find() methods.

key-value-pair-mongoDB

Documents in ‘info’ collection

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
> db.info.find().forEach(printjson)
{
        "_id" : ObjectId("517e829d005b19f1f0d96b25"),
        "name" : "Apple",
        "product" : "iPhone5S",
        "emp_no" : "100"
}
{
        "_id" : ObjectId("517e8377005b19f1f0d96b26"),
        "name" : "Technotip",
        "product" : "Video Tutorials - Educational",
        "emp" : [
                "Satish",
                "Kiran"
        ],
        "videos" : {
                "mongo" : "MongoDB Videos",
                "php" : "PHP Video Tutorials"
        }
}

Learn Create and Insert Documents: MongoDB.

Note:
find() returns cursor objects.
findOne() returns single object.

We can use findOne() method to select and retrieve only one record at a time.

findOne() Method

1
2
3
4
5
6
7
8
> db.info.findOne({name: 'Technotip'}).product
Video Tutorials - Educational
 
> db.info.findOne({name: 'Technotip'}).videos
{ "mongo" : "MongoDB Videos", "php" : "PHP Video Tutorials" }
 
> db.info.findOne({name: 'Technotip'}).emp;
[ "Satish", "Kiran" ]

Syntax for retrieving normal {key: value} pair, sub-object {key: value} pair and array {key: value} pair is same.

Limitation
Using findOne() method, we could select and return only 1 {key: value} pair.

To select and return more than 1 {key: value} pair, we can make use of find() method, with 2 parameters.

SELECT Columns or Fields ( { KEY: VALUE } ): MongoDB


[youtube https://www.youtube.com/watch?v=u0WGmvJFFy4]

YouTube Link: https://www.youtube.com/watch?v=u0WGmvJFFy4 [Watch the Video In Full Screen.]



find() Method, with two parameters

1
2
> db.info.find({name: 'Apple'}, {product: 1}).forEach(printjson);
{ "_id" : ObjectId("517e829d005b19f1f0d96b25"), "product" : "iPhone5S" }

First parameter is the condition, second parameter specifies the {key: value} pairs.

We can pass more than 1 key in second parameter; that would returns multiple {key: value} pairs.

1
2
3
4
5
6
> db.info.find({name: 'Apple'}, {product: 1, emp_no: 1}).forEach(printjson);
{
        "_id" : ObjectId("517e829d005b19f1f0d96b25"),
        "product" : "iPhone5S",
        "emp_no" : "100"
}

1 or true means, those {key: value} pairs need to be returned.
0 or false means, excluding those {key: value} pairs, all other {key: value} pairs(records) needs to be returned.

true(0)

1
2
3
4
5
6
7
8
> db.info.find({name: 'Apple'}, {product: true}).forEach(printjson);
{ "_id" : ObjectId("517e829d005b19f1f0d96b25"), "product" : "iPhone5S" }
> db.info.find({name: 'Apple'}, {product: true, emp_no: true}).forEach(printjson);
{
        "_id" : ObjectId("517e829d005b19f1f0d96b25"),
        "product" : "iPhone5S",
        "emp_no" : "100"
}

False(0): Exclusion

1
2
> db.info.find({name: 'Apple'}, {product: 0, emp_no: 0}).forEach(printjson);
{ "_id" : ObjectId("517e829d005b19f1f0d96b25"), "name" : "Apple" }

Note:
True and False combination doesn’t work

1
2
3
4
5
6
7
8
9
10
11
12
> db.info.find({name: 'Apple'}, {product: true, emp_no: false}).forEach(printjson);
Wed May 08 12:11:30.184 JavaScript execution failed: error: {
        "$err" : "You cannot currently mix including and excluding fields. 
                  Contact us if this is an issue.",
        "code" : 10053
} at src/mongo/shell/query.js:L128
> db.info.find({name: 'Apple'}, {product: 0, emp_no: 1}).forEach(printjson);
Wed May 08 12:11:40.840 JavaScript execution failed: error: {
        "$err" : "You cannot currently mix including and excluding fields. 
                  Contact us if this is an issue.",
        "code" : 10053
} at src/mongo/shell/query.js:L128

We can not combine true(1) and false(0) together in the second parameter.

Special Provision!
But we can do it with _id(ObjectId)

1
2
3
> db.info.find({name: 'Apple'}, 
               {product: 1, emp_no: 1, _id: 0}).forEach(printjson);
{ "product" : "iPhone5S", "emp_no" : "100" }

Operation of second document/record in ‘info’ collection.
This illustrates that the syntax for sub-objects, array and the normal key/value pair is same.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
> db.info.find({name: 'Technotip'}, {product: 1}).forEach(printjson);
{
        "_id" : ObjectId("517e8377005b19f1f0d96b26"),
        "product" : "Video Tutorials - Educational"
}
{ "_id" : ObjectId("518363e2d73694e289255486") }
> db.info.find({name: 'Technotip'}, {product: 1, videos: 1}).forEach(printjson);
 
{
        "_id" : ObjectId("517e8377005b19f1f0d96b26"),
        "product" : "Video Tutorials - Educational",
        "videos" : {
                "mongo" : "MongoDB Videos",
                "php" : "PHP Video Tutorials"
        }
}
 
> db.info.find({name: 'Technotip'}, 
               {product: 1, videos: 1, emp: 1}).forEach(printjson);
{
        "_id" : ObjectId("517e8377005b19f1f0d96b26"),
        "product" : "Video Tutorials - Educational",
        "emp" : [
                "Satish",
                "Kiran"
        ],
        "videos" : {
                "mongo" : "MongoDB Videos",
                "php" : "PHP Video Tutorials"
        }
}
 
> db.info.find({name: 'Technotip'}, 
               {product: 1, videos: 1, emp: 1, _id: 0}).forEach(printjson);
{
        "product" : "Video Tutorials - Educational",
        "emp" : [
                "Satish",
                "Kiran"
        ],
        "videos" : {
                "mongo" : "MongoDB Videos",
                "php" : "PHP Video Tutorials"
        }
}

Note:
Two documents with same name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
        "_id" : ObjectId("517e8377005b19f1f0d96b26"),
        "name" : "Technotip",
        "product" : "Video Tutorials - Educational",
        "emp" : [
                "Satish",
                "Kiran"
        ],
        "videos" : {
                "mongo" : "MongoDB Videos",
                "php" : "PHP Video Tutorials"
        }
}
{ "_id" : ObjectId("518363e2d73694e289255486"), "name" : "Technotip" }
1
2
> db.info.findOne({name: 'Technotip'})._id;
ObjectId("517e8377005b19f1f0d96b26")

If we use findOne() method on this collection, and the condition being the name key, then the oldest document will be returned.
Only one key: value pair is returned, as findOne() returns only single object.

Relationship Between Collections/Tables: MongoDB

In this video tutorial we shall learn about normalization, and the way mongoDB handles relationship between two collections(Primary Key and Foreign Key concept in RDBMS)

Normalization: It refers to the process of organizing the data to minimize redundancy and dependency.

There is no 1 way of doing this in mongoDB. You could implement it according to the needs of your application.

For Example, Normalization is good in the application wherein we do more of write operation. De-normalization is good, wherein we only read.

In today’s tutorial, we shall see how we can implement relationship between two collections/tables and query the database using this relationship.

Database name: company
Collections: info, ceo

mongoDB-database-collection

info collection

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
>use company
switched to db company
 
>db.info.find().forEach(printjson)
{
"_id" : ObjectId("517e829d005b19f1f0d96b25"),
"name" : "Apple",
"product": "iPhone5S",
"emp_no" : 100
}
 
{
"_id" : ObjectId("517e8377005b19f1f0d96b26"),
"name" : "Technotip",
"product": "Video Tutorials - Educational",
"emp" : [
"Satish",
"Kiran"
],
"Videos" : {
"mongo" : "MongoDB Videos",
"php": "PHP Video Tutorials"
}
}

Create another collection ceo and insert a document

1
2
3
4
5
6
7
8
9
10
>db.ceo.insert({
      name      : "SATISH",
      company_id: db.info.find()[1]._id
});
>db.ceo.find().forEach(printjson)
{
        "_id" : ObjectId("51822e2c60e925795355fd26"),
        "name" : "SATISH",
        "company_id" : ObjectId("517e8377005b19f1f0d96b26")
}

Here we store the _id value present in the second record of info collection inside first record’s company_id field of ceo collection.
This way we build a relation between two collections info and ceo.

Next, we query mongoDB to get some results based on this relationship.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> db.info.find({ _id: db.ceo.find()[0].company_id }).forEach(printjson)
{
        "_id" : ObjectId("517e8377005b19f1f0d96b26"),
        "name" : "Technotip",
        "product" : "Video Tutorials - Educational",
        "emp" : [
                "Satish",
                "Kiran"
        ],
        "videos" : {
                "mongo" : "MongoDB Videos",
                "php" : "PHP Video Tutorials"
        }
}
>

This command(in first line) retrieves the document in the ‘info’ collection which matches the company_id value present in ceo collection and _id of info collection.

Primary Key and Foreign Key Concept in MongoDB


[youtube https://www.youtube.com/watch?v=7cYT0Qbu9tU]

YouTube Link: https://www.youtube.com/watch?v=7cYT0Qbu9tU [Watch the Video In Full Screen.]



Note: In traditional database systems(RDBMS) we accomplish the same by using primary key and foreign key concept. And make use of JOINS (Equi JOIN, RIGHT JOIN, LEFT JOIN) to query the database, which actually consumes more time and resources. In mongoDB, there is no need of JOIN’s and hence is faster than RDBMS.