Professional Documents
Culture Documents
Journey To The Mongodb: Myat Su Htwe Senior Lecturer Academic Department
Journey To The Mongodb: Myat Su Htwe Senior Lecturer Academic Department
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?
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
1 Kyaw Lay 19 3 Su Su 18
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
5/19/2018
Concept
When I say Think
Document Row
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: “susu@gmail.com” 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
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()
db.collection_name.updateMany()
5/19/2018
Update Document in a collection
Eg.
Db.students.updateMany( collection
5/19/2018
Delete Document in a collection
Delete a Single document
db.collection_name.deleteOne()
db.collection_name.deleteMany()
5/19/2018
Delete Document in a collection
Eg.
Db.students.deleteMany( collection
5/19/2018
Select Document in a collection
Select all documents
db.collection_name.find()
Eg.,
Db.students.find( collection
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