0% found this document useful (0 votes)
53 views44 pages

Journey To The Mongodb: Myat Su Htwe Senior Lecturer Academic Department

The document discusses MongoDB, a scalable and high-performance NoSQL database that uses documents with dynamic schemas and is organized into collections and databases. It covers MongoDB features like indexing, replication, document storage, querying, sharding and more. Examples are provided to explain concepts like collections, documents, fields, linking and embedding in MongoDB.

Uploaded by

Invisible Side
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views44 pages

Journey To The Mongodb: Myat Su Htwe Senior Lecturer Academic Department

The document discusses MongoDB, a scalable and high-performance NoSQL database that uses documents with dynamic schemas and is organized into collections and databases. It covers MongoDB features like indexing, replication, document storage, querying, sharding and more. Examples are provided to explain concepts like collections, documents, fields, linking and embedding in MongoDB.

Uploaded by

Invisible Side
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Journey to the MongoDB

Myat Su Htwe
Senior Lecturer
Academic Department

5/19/2018
What is NoSQL?
Is a class of DBMS
Interpreted as “No SQL” and most translate it
as “Not Only SQL”
Encompasses a wide variety of different
database technologies that were developed in
response to the demands presented in
building modern applications

5/19/2018
Different Type of NoSQL Databases
Key-value store
something that stores a value

Document-based store
more flexible about stored data

Column-based store
aggregating data

Graph-based
targeting use cases, like relationships

5/19/2018
5/19/2018
What is MongoDB?

MongoDB (form humongous) is a scalable,


high-performance, open source, schema-free,
document-oriented database.
• -mongodb.org

5/19/2018
About Mongo
Developed by 10gen
Founded in 2007
A document-oriented
Written in C++
Support APIs (drivers) in many computing
language
JavaScrpt, Python, Ruby, Perl, Java, Java ,
JavaScala, C#, C++, Haskell, Erlang

5/19/2018
FEATURES

5/19/2018
Features
Standard database stuff
Indexing
Replication/ failover support

5/19/2018
Features
Document Storage
Documents are stored in BSON (binary JSON)
BSON is a binary serialization of JSON-like objects
This is extremely powerful, because it means mongo
understands JSON natively

5/19/2018
Features
Schema-less; very flexible
No more blocking ALTER TABLE

5/19/2018
Features
Auto-sharding
Makes for easy horizontal scaling

5/19/2018
Features: Sharding

ID Name Age

1 Kyaw Lay 19

2 Myint Myat 20

3 Su Su 18

4 Thuzar 21

DB Sharding

Shard #1 Shard #2

ID Name Age ID Name Age

1 Kyaw Lay 19 3 Su Su 18

2 Myint Myat 20 4 Thuzar 21

5/19/2018
Features
Strong with major languages
JavaScrpt, Python, Ruby, Perl, Java, Java ,
JavaScala, C#, C++, Haskell, Erlang

5/19/2018
Features
Querying
javascript-based query syntax
• Allow us to deep, nested queries

db.students.find({})

5/19/2018
CONCEPT

5/19/2018
Concept
When I say Think
Database Database

5/19/2018
Concept
When I say Think
Collection Table

Name:Aye Name Age Gender


Name:BoBo
Cname:Chaw
Name: Doe Aye Aye 16 F
Su Lone
Bo Bo 20 M
Age: 20
Gender: M Chaw Su 19 F
Doe Lone 18 M

5/19/2018
Concept
When I say Think
Document Row

Name Age Gender


Name: Aye Aye
Age: 16 Aye Aye 16 F
Gender: F Bo Bo 20 M
Chaw Su 19 F
Doe Lone 18 M

Maximum document size is 16 MB.


5/19/2018
Concept
When I say Think
Field Column

Name Age Gender


Aye Aye 16 F
Name:Aye Aye
Bo Bo 20 M
Age: 16
Gender: F Chaw Su 19 F
Doe Lone 18 M

FIELD
Column
5/19/2018
Name: Aye 0 or more databases
Aye
Age: 16 0 or more collections
Gender: F
Name: Aye
Name: 0 or more
Aye Name: Bo Bo
Age: documents
Age: Age:
16 20
Gender:
Gender: F
Gender: M
Name: Bo Bo
Age: 20
Gender: M

5/19/2018
Concept
When I say Think
• Linking & Embedding • Joining

{
_id:<Objectid1>,
name: “Su Su”,
contact:{

phone:”091234567”,
email: “[email protected]” Embedded Document
},
address:{
Township:”Latha”,
City:”Yangon”
}
}
5/19/2018
Concept
When I say Think
Sharding (Range Partition , Partition
add more servers)

Single Collection
(5 billion documents)

SHARDED

SHARD A SHARD B SHARD C SHARD D SHARD E


1 billion 1 billion 1 billion 1 billion 1 billion

5/19/2018
Concept
When I say Think
ReplSet Replication

Primary
1

Secondary Secondary

2 3
5/19/2018
APPLICATION

5/19/2018
Good For:
E-commerce product catalog
Blogs and content management
Mobile and social networking sites
Etc.,

5/19/2018
CRUD

5/19/2018
CREATE DATABASE
Does not provide any command to create a
new database
It provides ‘USE’ command:
It will create new database or
Open an existing database

USE myDB;

5/19/2018
DROP Database
dropDatabase()
Will delete the selected database.

Db.dropDatabase();

5/19/2018
CREATE Collection
Create collection automatically when you insert
any document using the insert() method.

db.Collection_Name.insert();

Eg.,
db.colleges.insert({name:”GUSTO”});

5/19/2018
DROP Collection
Create collection automatically when you
insert any document using the drop() method.

db.Collction_Name.drop();

Eg.,
db.colleges.drop();

5/19/2018
Insert Document in a collection
Insert a Single document

db.collection_name.insertOne()

Eg.
db.students.insertOne( collection
{
name:”Aung Min Phyo”, field: value
age: 18, field: value document
gender: “M” field: value
}
)

5/19/2018
Insert Document in a collection
Insert Multiple documents

db.collection_name.insertMany()

db.students.insertMany( collection
{
name:”Aung Min Phyo”, document
age: 18,
gender: “M”
},
{
name:”Yadana Ko Ko”, document
age: 20,
gender: “F”
}
)
5/19/2018
Update Document in a collection
Update a Single document

db.collection_name.updateOne()

Update Multiple Documents

db.collection_name.updateMany()

5/19/2018
Update Document in a collection
Eg.

Db.students.updateMany( collection

{age:{$lt:18}}, Update filter


{$set: {name:”Someone”}} Update action

5/19/2018
Delete Document in a collection
Delete a Single document

db.collection_name.deleteOne()

Delete Multiple Documents

db.collection_name.deleteMany()

5/19/2018
Delete Document in a collection
Eg.

Db.students.deleteMany( collection

{gender:”M”} Delete filter

5/19/2018
Select Document in a collection
Select all documents

db.collection_name.find()

Eg.,
Db.students.find( collection

{age: {$gt: 18}}, Query criteria


{name:1, gender: 1} projection
)
5/19/2018
OPERATOR

5/19/2018
Comparison
Name Description
$eq = Matches values that are equal to a specific value.
$gt > Matches values that are greater than a specific
value.
$gte >= Matches values that are greater than or equal to
a specific value.
$lt < Matches values that are less than a specific
value.
$lte <= Matches values that are less than or equal toa
specific value.
$ne != Matches values that are not equal to a specific
value.
$in IN() Matches any of the values specify in an array
$nin NOT IN() Matches none of the values specify in an array
5/19/2018
Logical
Name Description
$and AND Returns all documents that match the conditions
of both clauses
$or OR Returns all documents that match the conditions
of either clauses
$not NOT Invert the effect of a query expression and
returns documents that are not match the query
expression

5/19/2018
References
https://www.3pillarglobal.com/insights/just-
say-yes-to-nosql
https://www.tutorialsjar.com/mongodb-
update-documents-crud/
https://www.mongodb.com/nosql-explained

5/19/2018
Further Reading
The Little MongoDB Book
MongoDB Notes for Professional
Mongodb Architecture Guide
https://medium.com/s-c-a-l-e/mongodb-co-
creator-explains-why-nosql-came-to-be-and-
why-open-source-mastery-is-an-elusive-goal-
3a138480b9cd

5/19/2018
Download Link
for MongoDB installer
https://www.filehorse.com/download-
mongodb/33269/

5/19/2018
5/19/2018

You might also like