Uploaded on Oct 2, 2019
MongoDB is a scalable high-performance open-source document-orientated database which is built for speed, rich document based queries for easy readability, full index support for high performance, replication and failover for high availability, auto sharding for easy scalability and map/reduce for aggregation.
MongoDB Introduction, Installation & Execution
MongoDB
iFour Consultancy
Introduction, Installation & Execution
https://www.ifourtechnolab.com
What is MongoDB ?
Scalable High-Performance Open-source, Document-orientated
database.
Built for Speed
Rich Document based queries for Easy readability.
Full Index Support for High Performance.
Replication and Failover for High Availability.
Auto Sharding for Easy Scalability.
Map / Reduce for Aggregation.
https://www.ifourtechnolab.com
Why use MongoDB?
SQL was invented in the 70’s to store data.
MongoDB stores documents (or) objects.
Now-a-days, everyone works with objects (Python/Ruby/Java/etc.)
And we need Databases to persist our objects. Then why not store
objects directly ?
Embedded documents and arrays reduce need for joins. No Joins
and No-multi document transactions.
https://www.ifourtechnolab.com
What is MongoDB great for?
RDBMS replacement for Web Applications.
Semi-structured Content Management.
Real-time Analytics & High-Speed Logging.
Caching and High Scalability
Web 2.0, Media, SAAS, Gaming
HealthCare, Finance, Telecom, Government
https://www.ifourtechnolab.com
Not great for?
Highly Transactional Applications.
Problems requiring SQL.
Some Companies using MongoDB in
Production
https://www.ifourtechnolab.com
Advantages of MongoDB
Schema less : Number of fields, content and size of the
document can be differ from one document to another.
No complex joins
Data is stored as JSON style
Index on any attribute
Replication and High availability
https://www.ifourtechnolab.com
MongoDB Terminologies for RDBMS concepts
RDBMS MongoDB
Database Database
Table, View Collection
Row Document (JSON, BSON) 7
Column Field
Index Index
Join Embedded Document
Foreign Key Reference
Partition Shard
https://www.ifourtechnolab.com
JSON
“JavaScript Object Notation”
Easy for humans to write/read, easy for computers to
parse/generate
Objects can be nested
Built on
• name/value pairs
• Ordered list of values
http://json.org/
https://www.ifourtechnolab.com
BSON
“Binary JSON”
Binary-encoded serialization of JSON-like docs
Embedded structure reduces need for joins
Goals
• Lightweight
• Traversable
• Efficient (decoding and encoding)
http://bsonspec.org/
https://www.ifourtechnolab.com
BSON Example
{
"_id" : "37010"
“City" : “Nashik",
“Pin" : 423201,
"state" : “MH",
“Postman” : {
name: “Ramesh Jadhav”
address: “Panchavati”
}
}
https://www.ifourtechnolab.com
Data Types of MongoDB
Integer
Date Boolean
Binary
data Double
Object ID String
Null Arrays
https://www.ifourtechnolab.com
Data Types
String : This is most commonly used datatype to store the data. String in
mongodb must be UTF-8 valid.
Integer : This type is used to store a numerical value. Integer can be 32 bit or
64 bit depending upon your server.
Boolean : This type is used to store a boolean (true/ false) value.
Double : This type is used to store floating point values.
Min/ Max keys : This type is used to compare a value against the lowest and
highest BSON elements.
Arrays : This type is used to store arrays or list or multiple values into one key.
Timestamp : ctimestamp. This can be handy for recording when a document
has been modified or added.
Object : This datatype is used for embedded documents.
https://www.ifourtechnolab.com
Data Types
Null : This type is used to store a Null value.
Symbol : This datatype is used identically to a string however, it's
generally reserved for languages that use a specific symbol type.
Date : This datatype is used to store the current date or time in
UNIX time format. You can specify your own date time by creating
object of Date and passing day, month, year into it.
Object ID : This datatype is used to store the document’s ID.
Binary data : This datatype is used to store binay data.
Code : This datatype is used to store javascript code into document.
Regular expression : This datatype is used to store regular
expression
https://www.ifourtechnolab.com
Installation in Windows
Download MongoDB from Website:
https://www.mongodb.org/downloads
Select option
Windows
Download and Run
https://www.ifourtechnolab.com
Starting MongoDB in Windows
Create one folder (eg SNJB) in bin folder of MongoDB
Goto command prompt
Goto bin dir of MongoDB and write following command
mongod --storageEngine=mmapv1 --dbpath SNJB
(Server will started and listen at 27017 port)
Open another command prompt and give command mongo
(Client will be started)
https://www.ifourtechnolab.com
Installation in Ubuntu
Download MongoDB from Website:
https://www.mongodb.org/downloads
Select option
Linux
Download and Run
https://www.ifourtechnolab.com
Starting MongoDB in Ubuntu
Create a folder in bin directory of mongodb
Open terminal
Goto mongodb bin folder (cd mongo….)
Type ./mongod (Server is started)
Open another terminal
Goto mongodb bin folder (cd mongo….)
Type ./mongo (client will be started)
Run all commands on client terminal
https://www.ifourtechnolab.com
Outline
Difference Between SQL and NoSQL
Study of Open Source NOSQL
Database
MongoDB Installation,
Basic CRUD operations,
Execution
https://www.ifourtechnolab.com
Basic Database Operations
Database
collection
https://www.ifourtechnolab.com
Basic Database Operations- Database
use ciommand
•
db To check currently selected database use the command db
show dbs • Displays the list of databases
db.dropDatabas • To Drop the database
e()
https://www.ifourtechnolab.com
Basic Database Operations- Collection
db.createCollection (name)
• To create collection
Ex:- db.createCollection(Stud)
• List out all names of collection in current
>show collections database
db.databasename.insert • In mongodb you don't need to
create collection. MongoDB
({Key : Value}) creates collection automatically,
Ex:- db.Stud.insert({{Name:”Jiya”}) when you insert some document.
db.collection.drop() • MongoDB's db.collection.drop() is used to
Example:-
drop a collection from the database.
db.Stud.drop()
https://www.ifourtechnolab.com
Comments