Wednesday, October 15, 2014

MongoDB CRUD


Create/Insert

> db.Employee.insert({Name:"Supreet",Empid:199380,Designation:"Associate Consultant"})
WriteResult({ "nInserted" : 1 })
> db.Employee.insert({Name:"Tom",Empid:199381,Designation:"Project Engineer"})
WriteResult({ "nInserted" : 1 })

Select All documents

> db.Employee.find()
{
"_id" : ObjectId("540d4a2a4069474f1248f63f"),
"Empid" : 199380,
"Name" : "Supreet",
"Designation" : "Associate Consultant"
}
{
"_id" : ObjectId("540d4a654069474f1248f64b"),
"Empid" : 199381,
"Name" : "Tom",
"Designation" : "Project Engineer"
}

Update a document

> db.Employee.update({Empid:199381},{$set:{Designation:"Technical Lead"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })


> db.Employee.find()
{
"_id" : ObjectId("540d4a2a4069474f1248f63f"),
"Empid" : 199380,
"Name" : "Supreet",
"Designation" : "Associate Consultant"
}
{
"_id" : ObjectId("540d4a654069474f1248f64b"),
"Empid" : 199381,
"Name" : "Tom",
"Designation" : "Technical Lead"
}


remove a document


> db.Employee.remove({Empid:199381})
WriteResult({ "nRemoved" : 1 })
> db.Employee.find()
{
"_id" : ObjectId("540d4a2a4069474f1248f63f"),
"Empid" : 199380,
"Name" : "Supreet",
"Designation" : "Associate Consultant"
}
show all collections(tables) in the database

> show collections
Employee

using OR operator

> db.Employee.find({$or:[{Empid:199380},{Name:"Supreet"}]})
{
"_id" : ObjectId("540d4a2a4069474f1248f63f"),
"Empid" : 199380,
"Name" : "Supreet",
"Designation" : "Associate Consultant"
}

Using Greater than operator

> db.Employee.find({ Empid:{$gt:199379}})
{
"_id" : ObjectId("540d4a2a4069474f1248f63f"),
"Empid" : 199380,
"Name" : "Supreet",
"Designation" : "Associate Consultant"
}

db.products.find({"Price":{$gt:20000}})
/* 0 */
{
    "_id" : ObjectId("55923c10f7928010b0bd8a81"),
    "Name" : "Ego",
    "Category" : "Laptops",
    "Price" : 50000
}

/* 1 */
{
    "_id" : ObjectId("55923c3ef7928010b0bd8a82"),
    "Name" : "Sony1",
    "Category" : "Laptops",
    "Price" : 60000
}

HTML 5 and css 3 for absolute beginners

all we need to start with is :

text editor: Notepad++. did i mention its free?
web-browser: Google Chrome
Ambition

Here is my HTML code

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="stylefile.css">
</head>
<body>
<div id="big_wrapper">
<header id="top_banner">
<h1>Welcome to my new WebSite</h1>
</header>
<nav id ="Menu">
<ul>
<li>Home</li>
<li>Tutorials</li>
<li>Contact Us</li>

</ul>
</nav>
<section id ="main_section">
<article>
<header>
<hgroup>
<h1>HTML5 Overview</h1>
<br>
<h2>HTML5 is the next major revision of the HTML standard superseding HTML 4.01, XHTML 1.0, and
XHTML 1.1. HTML5 is a standard for structuring and presenting content on the World Wide Web.</h2>
</hgroup>
<header>
</article>
<footer id ="foot">
<p>Created By Supreet</p>
</footer>

</section>

</div>
</body>
</html>

CSS
styling the boring lame webiste

1) setting margins and padding to 0px to all tags because some elements have default margins and padding. below code will reset to zero

*{
margin : 0px;
padding: 0px;
}
Rest of the css code:

body
{
text-align:center;
}
#big_wrapper
{
Margin:20px auto;
border: 1px solid black;
width:1000px;
text-align:left

}
#top_banner
{
background-color:cyan;
font-family:Tahoma;
padding:20px;
border:1px bold
}

#Menu li
{
display:inline-block;
padding:5px;
font:bold 12px Tahoma;


}
#Menu
{
background-color:grey;

}
h1{
font:bold 20px Tahoma;

}
h2
{
font:bold 14px Tahoma;
}
header,section,footer,aside,hgroup
{
display:block;
}
#foot
{
text-align:center;
padding:20px;
border:1px solid black;
font:bold 12px Tahoma;
}