Unit-4 MongoDB Students
Unit-4 MongoDB Students
Unit-4 MongoDB Students
• SQL vs NoSQL
• NoSQL Features & Types
• What is MongoDB?
• MongoDB Features
• MongoDB Data Types
• Installation MongoDB on Windows
Ajay Parashar
• MongoDB CRUD Operations
IT@ HCST
• Node.js with MongoDB
These databases have fixed or static or predefined schema They have dynamic schema
These databases are best suited for complex queries These databases are not so good for complex queries
FEATURES
Key-value stores, or key-value databases, implement a simple data model that pairs
a unique key with an associated value.
Key-value stores e.g.
• Redis, Cassandra
Document databases, also called document stores, store semi-structured data and
descriptions of that data in document format.
Document oriented e.g.
• MongoDB, CouchDB
What is MongoDB?
and for the cloud.
A database management
system designed to
rapidly develop web MongoDB stores data
A general-purpose as JSON/BSON (Binary
applications and internet Document-Oriented, Database Collections
document database JSON) documents
infrastructure. No Sequel (NoSQL)
designed for modern
application development
and for the cloud.
Auto
MongoDB Features
Indexing
Replication
High Horizontal
Availability Scalability
Load
Balancing
Ajay Parashar IT@HCST Ajay Parashar IT@HCST
• String
This is the 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.
MongoDB Data Types • Double
This type is used to store floating point values.
• 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.
• Boolean
This type is used to store a boolean (true/ false) value.
Ajay Parashar IT@HCST Ajay Parashar IT@HCST
• Object ID
This datatype is used to store the document’s ID.
• Array
This type is used to store arrays or list or multiple values into one key.
• Timestamp
This can be handy for recording when a document has been modified or added. Installation MongoDB on Windows
• Code
This datatype is used to store JavaScript code into the document.
• Regular Expression
This datatype is used to store regular expression.
• When the setup asks you to choose the • Click Next when the MongoDB service
Setup type, choose Complete. configuration. MongoDB will be
installed in the windows service
RDBMS MongoDB
Database Database
Table Collection
column Field
Primary Key
Primary Key
(Default key _id provided by MongoDB itself)
• SQL Server
CREATE DATABASE databasename; INSERT DOCUMENT
Example: CREATE DATABASE testdb;
• MySQL
✓ Single
INSERT INTO tablename (c1,c2,...)
VALUES (v11,v12,...);
✓ Multiple
INSERT INTO tablename (c1,c2,...)
VALUES (v11,v12,...), (v21,v22,...), ….. , (vnn,vn2,...);
$lte Matches values that are less than or equal to a specified value.
$ne Matches all values that are not equal to a specified value.
$gt $gte
Select All Documents
{ field: { $gt: value } } { field: { $gte: value } }
SELECT * FROM tablename WHERE column;
$nin
{ field: { $nin: [ <value1>, <value2>, ..., <valueN> ] } }
Ajay Parashar IT@HCST Ajay Parashar IT@HCST
Joins query clauses with a logical AND returns all documents that
$and
match the conditions of both clauses.
$or
QUERY DOCUMENTS
{ $or: [ { <expr1> }, { <expr2> }, ... , { <exprN> } ] }
$and
{ $and: [ { <expr1> }, { <expr2> }, ... , { <exprN> } ] } Specify “OR” Conditions
• MySQL
UPDATE table_name
SET
column_name1 = expr1,
column_name2 = expr2,
...
WHERE condition;
Ajay Parashar IT@HCST Ajay Parashar IT@HCST
Multiple Update
Updates all documents
that match the specified
filter for a collection.
Replace One
Replaces a single
document within the
collection based on the
filter.
DELETE DOCUMENTS
• SQL Server
DELETE FROM table_name WHERE condition;
Single Delete
• MySQL
DELETE FROM table_name WHERE condition;
Multiple Delete
DELETE DOCUMENTS
Thank You!