01 Overview
01 Overview
Overview of NoSQL
1
Database Management System
References
2
Learning objectives
3
Contents
4
1. SQL and NoSQL database
6
1. SQL and NoSQL database
Key-Value stores
7
1. SQL and NoSQL database
Graph databases
8
1. SQL and NoSQL database
Column-oriented databases
Example
9
1. SQL and NoSQL database
Document stores
10
1. SQL and NoSQL database
Comparison
Data storage model Data is stored in rows and The data is stored in
columns in a table, where different formats,
each column is of a depending on the provider.
specific type. The standard storage
Joins are used to retrieve structures are documents,
data from multiple tables. graphs, key-values, and
wide columns.
11
1. SQL and NoSQL database
Comparison
13
2. What is MongoDB?
15
3. MongoDB features
▪ Queries
o By field
o By regular expression
o By user defined java script functions
o By range
▪ Indexes
o Primary and secondary
o Any document field
16
3. MongoDB features
▪ Replication
o Creates multiple copies of the data and sends these copies to a
different server so that if one server fails, then the data is retrieved
from another server
▪ Sharding
o A method for distributing or partitioning data across multiple machines
o It is useful when no single machine can handle large modern-day
workloads, by allowing you to scale horizontally
▪ Load balancing
o Via horizontal scaling features like replication and sharding
17
3. MongoDB features
18
Contents
19
4. Key components of MongoDB
Document databases
▪ A database server
o has many databases
▪ A database
o has many collections
▪ A collection
o has many documents
▪ A document
o consist of field-value pairs which
are the basic unit of data
20
4. Key components of MongoDB
▪ Document
o Composed of field-and-value pairs, the values of fields may include
numbers, strings, booleans, arrays, nested documents, or arrays of
documents.
o Every document in the collection has a unique key: "_id"
Document structure: Example:
21
4. Key components of MongoDB
▪ Document
Example:
{
_id: ObjectId("5099803df3f4948bd2f98391"),
name: { first: "Alan", last: "Turing" },
birth: new Date('Jun 23, 1912'),
death: new Date('Jun 07, 1954'),
contribs: [ "Turing machine", "Turing test", "Turingery" ],
views : NumberLong(1250000)
}
22
4. Key components of MongoDB
23
4. Key components of MongoDB
RDBMS MongoDB
Database Database
Table Collection
Row Document
Column Field
Table join Embedded documents
Primary key (Default key _id
Primary key provided by MongoDB itself)
24
Contents
25
5. MongoDB servers
▪ MongoDB Atlas
o used on the cloud as a managed service
▪ MongoDB Community Server
o free and available for Windows, Linux, and
macOS.
▪ MongoDB Enterprise Server
o the commercial edition of MongoDB, available
as part of the MongoDB Enterprise Advanced
subscription.
26
5. MongoDB servers
MongoDB Atlas
28
5. MongoDB editions
Installing & configuring MongoDB on Windows
29
5. MongoDB editions
Installing & configuring MongoDB on Windows
30
5. MongoDB editions
Installing & configuring MongoDB on Windows
31
5. MongoDB editions
Installing & configuring MongoDB on Windows
32
5. MongoDB editions
Installing & configuring MongoDB on Windows
▪ Select either:
o Run the service as Network Service user (Default): This is a Windows user
account that is built-in to Windows
o Run the service as a local or domain user
• For an existing local user account, specify a period for the Account Domain and
specify the Account Name and the Account Password for the user.
• For an existing domain user, specify the Account Domain, the Account Name
and the Account Password for that user.
o Service Name: Default name is MongoDB.
o Data Directory: Specify the data directory, which corresponds to the --
dbpath.
o Log Directory: Specify the Log directory, which corresponds to the --logpath.
33
5. MongoDB editions
Installing & configuring MongoDB on Windows
34
5. MongoDB editions
Installing & configuring MongoDB on Windows
▪ Click Finish
35
5. MongoDB editions
Installing & configuring MongoDB on Windows
36
5. MongoDB editions
Installing & configuring MongoDB on Windows
37
5. MongoDB editions
Installing & configuring MongoDB on Windows
38
5. MongoDB editions
Installing & configuring MongoDB on Windows
▪ Configuring MongoDB:
o Click New and add the path to your mongod.exe inside the installation
folder: C:\Program Files\MongoDB\Server\5.0\bin
o Click OK
39
5. MongoDB editions
Installing & configuring MongoDB on Windows
▪ Configuring MongoDB:
o Command Prompt and go to your MongoDB installation directory cd
C:\Program Files\MongoDB\Server\5.0\bin
40
5. MongoDB editions
Installing & configuring MongoDB on Windows
▪ Configuring MongoDB
o Start the MongoDB server by typing mongod.exe
41
Contents
42
6. MongoDB tools
▪ MongoDB Shell
o Easily query data, configure settings, and execute other actions with this
modern, extensible command-line interface — replete with syntax
highlighting, intelligent autocomplete, contextual help, and error
messages.
▪ MongoDB Compass
o A powerful GUI for querying, aggregating, and analyzing your MongoDB
data in a visual environment. Free to use, source available, and run on
macOS, Windows, Linux..
▪ MongoDB Atlas CLI
o manage MongoDB Atlas deployments from the command line
▪ …
43
6. MongoDB tools
MongoDB Shell (mongosh)
▪ Connect to a deployment:
o Connect to local MongoDB instance on default port:
• mongosh
o Connect to local MongoDB instance on non default port:
• mongosh --port 28015
• mongosh --host localhost:28015
o Connect mongoDB instance on a remote host:
• mongosh “mongodb://mongodb0.example.com:28015”
o Connecting to Atlas:
• mongosh "mongodb+srv://cluster0.msr5i.mongodb.net/myFirstDatabase" -u
mongobasic
6. MongoDB tools
MongoDB Shell (mongosh)
▪ Example
45
6. MongoDB tools
MongoDB Shell (mongosh)
47
Câu hỏi hiểu bài
49