2. SESSION:01
History of MondoDB
Till 1970 - Data Stored in Flat File Systems.
Flat files-No standard structure, Search is biggest problem
DBMS Database in Early 1980.
E.F.Codd's rule for RDBMS in Early 1990.
SQL is language to access database information.
Problem with RDBMS is
Data Volume is high, speed become slower.
Various type of information in uniform structure is difficult to
manage.
To overcome from this problems Document base database
is introduced as NoSQL database.
3. Databases can be divided in 3 types:
RDBMS (Relational Database Management System)
OLAP (Online Analytical Processing)
NoSQL (recently developed database)
SESSION:01
4. What is NoSQL Database
NoSQL Database is used to refer a non-SQL or non
relational database.
It provides a mechanism for storage and retrieval of
data other than tabular relations model used in
relational databases.
NoSQL database doesn't use tables for storing data. It
is generally used to store big data and real-time web
applications.
SESSION:01
5. Advantages of NoSQL
Automatic Failover
Horizontal Scaling - unlimited
JSON support
Expressive query language
Simple to learn for developers
Data as a code
Fast performance.
SESSION:01
6. What is MongoDB [1]
Mongo DB is an Open source product by 10gen - is
free to use.
MongoDB is a No SQL database.
Mongo DB is a document-oriented database.
NoSchema
Single Object Structure
JSON like BSON == Binary JSON
No Complex Join
SESSION:01
7. What is MongoDB [2]
MongoDB stores data in flexible, JSON-like documents,
meaning fields can vary from document to document and data
structure can be changed over time
The document model maps to the objects in your application
code, making data easy to work with
Ad hoc queries, indexing, and real time aggregation provide
powerful ways to access and analyze your data
MongoDB is a distributed database at its core, so high
availability, horizontal scaling, and geographic distribution are
built in and easy to use
SESSION:01
8. Term Comparisons with RDBMS
Document = Record
Collection = Table
Container = Database
Field = column (key : value pair)
SESSION:01
9. Document Structure
Example:
{
_id: 563479cc8a8a4246bd27d784,
customer_id: 11,
customer_name: Smith Taylor,
order_date: 20-Jun-2021
}
key component is : _id : object id
automatically assign by database
24 digits alpha-numeric
SESSION:01
10. Data Type Supports
String
Integer
Boolean
Double
Min/Max key
Arrays
Object
Null
Symbol
Date
SESSION:01
11. Download and Install MongoDB
http://www.mongodb.org/downloads (Register
and then donwload)
https://www.mongodb.com/try/download/commu
nity (Free trial version)
Default port of MongoDB server is 27017
connection : https://localhost:27017
SESSION:01
12. Start MongoDB
JavaScript Driver : bin folder -> mongo.exe
it will prompt for javascript prompt >
write a sample javascript code i.e.
> var name="Jainul"
> print("My Name: ",name);
My Name: Jainul <<--- OUTPUT
>
SESSION:01
13. Use GUI MongoDB
Use MongoDB GUI by installing MongoDB Compass
It will install "mongodb-compass...exe" in bin
folder
It will run and provide GUI interface to interact
with database
You can use Robo 3T / Studio 3T a GUI for
https://robomongo.org/
SESSION:01
14. Connecting MongoDB with front end
--------JavaScript code for connection ------------
import { MongoClient } from 'mongodb'
export async function connect () {
// Connection URL
const url = 'mongodb://localhost:27017/my_database'
let db
try {
db = await MongoClient.connect(url)
console.log('Connected successfully!')
} catch (err) {
// Handle error
}
return db
}
SESSION:01
15. Connecting MongoDB with front end
============ C# connectivity =============
var client = new MongoClient();
var database = client.GetDatabase("test");
var collection =
database.GetCollection("restaurants");
------------------------------------------------------------
SESSION:01