KEMBAR78
Introduction to MongoDB.pptx
Introduction to
MongoDB
Surya Prakash
Gupta
Agenda
Presentation Title
Introduction to MongoDB 2
 What is NoSQL?
 Types of NoSQL
 SQL Vs NoSQL
 When to use NoSQL?
 What is MongoDB?
 Features of MongoDB
 MongoDB Data types
 Who’s using MongoDB?
 MongoDB terms
 MongoDB Installation
 Some MongoDB commands
 MongoDB Compass & MongoDB
Atlas
 References
What is NoSQL Database?
Introduction to MongoDB 3
 The term “NoSQL database” refer to any “Non-relational” or “Not only SQL” databases
provides a mechanism for storage and retrieval of data in a format 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.
 Flexible schema i.e., no predefined or rigid schema.
 It avoids joins and is easy to scale.
Types of NoSQL Database
Introduction to MongoDB 4
NoSQL Databases are mainly categorized into four types: Key-value pair, Column-oriented,
Graph-based & Document-oriented.
SQL Vs NoSQL
Introduction to MongoDB 5
SQL NoSQL
SQL databases are primarily called
RDBMS or Relational Databases.
NoSQL databases are primarily called
as Non-relational or distributed
database.
SQL databases are table-based
databases.
NoSQL databases can be document
based, key-value pairs, graph
databases.
Vertical Scalability Horizontal Scalability
Fixed or Predefined schema. Flexible schema.
Not suitable for hierarchical data storage. Suitable for hierarchical data storage.
Oracle, MySQL, Microsoft SQL Server,
and PostgreSQL.
Document: MongoDB and CouchDB,
Key-value: Redis and DynamoDB,
Column-based: Cassandra and HBase,
Graph: Neo4j and Amazon Neptune.
When to use NoSQL?
Introduction to MongoDB 6
1. When a huge amount of data needs to be stored and retrieved.
2. The relationship between the data you store is not that important
3. The data changes over time and is not structured.
4. Constraints and Joins support is not required at database level.
5. The data is growing continuously, and you need to scale the database regularly to handle
the data.
What is MongoDB?
Introduction to MongoDB 7
 Most popular NoSQL database.
 Open-source document-oriented database.
 Its scale-out architecture allows you to meet the
increasing demand for your system by adding
more nodes to share the load.
 MongoDB uses BSON (Binary JSON) to query
database.
 Stores data in the form of BSON documents.
Features of MongoDB
Introduction to MongoDB 8
 Indexing: Efficient search & data processing in very less time.
 Scalability: MongoDB scales horizontally using sharding (partitioning data across various
servers). Also, new machines can be added to a running database.
 Replication & High Availability: Multiple copies of data is replicated on different servers
which protects the database from hardware failures. If one server goes down, the data can
be retrieved easily from other active servers which also had the data stored on them.
 Load balancing: It has an automatic load balancing configuration because of data placed in
shards.
 Aggregation: Aggregation operations process data records and return the computed
results. It is like the GROUPBY clause in SQL. A few aggregation expressions are sum, avg,
min, max, etc.
 Languages supported: The list of supported languages includes Node.js, C, C++,
C#, Go, Java, Perl, PHP, Python, Ruby, Rust, Scala, and Swift.
MongoDB Data Types
Introduction to MongoDB 9
Who’s is using MongoDB?
Introduction to MongoDB 10
MongoDB has been adopted as backend software by a few major websites and services
including Toyota, Cisco, Shutterfly, Adobe, Ericsson, Craigslist, eBay, and Foursquare.
MongoDB Terms
Introduction to MongoDB 11
 Databases: A database stores one or more collections of documents.
 Collections: MongoDB stores documents in collections. Collections are analogous to tables
in relational databases.
 Documents: MongoDB stores data records as BSON documents & similar to JSON
objects. It is analogous to row in relational databases. These are composed of field-and-value
pairs and have the following structure:
{
field1: value1,
field2: value2,
field3: value3,
...
fieldN: valueN
}
 Fields Names: These are strings analogous to column in relational databases.
Example
Introduction to MongoDB 12
SQL Vs MongoDB Terms
Introduction to MongoDB 13
MongoDB Installation
Introduction to MongoDB 14
 MongoDB is available in two server editions: Community and Enterprise.
 Community edition is free & Enterprise edition is a paid version and has some advanced
features.
 Installation links:
Install MongoDB — MongoDB Manual
Community: Try MongoDB Community Edition | MongoDB
Enterprise: Try MongoDB Enterprise Advanced | MongoDB
Create Database
Introduction to MongoDB 15
The use Database_name command makes a new database in the system if it does not exist, if
the database exists it uses that database.
For example, use mydb.
Now your database is ready of name mydb.
List all databases
Introduction to MongoDB 16
To list down all the databases, use the command below:
show dbs
This command lists down all the databases and their size on the disk.
mydb database is not created until you save a document in it.
Create Collection
Introduction to MongoDB 17
To create collection, use the command below:
db.createCollection(name, options)
name is name of collection to be created. Options is a document and is used to specify
configuration of collection such as capped, autoIndexId, size.
List all Collections
Introduction to MongoDB 18
To see all collections in a database, use the command below:
show collections
Drop Database & Collection
Introduction to MongoDB 19
 Use the following command to delete a database:
db.dropDatabase()
 Use the following command to delete a collection:
db.collection_name.drop()
Create Documents
Introduction to MongoDB 20
Two methods insert or create documents in collection:
1. db.collection_name.insertOne()
2. db.collection_name.insertMany()
Retrieving Documents
Introduction to MongoDB 21
 Use the below command to retrieve documents:
db.collection_name.find()
 For a proper formatted output, use the below command: pretty() with find().
db.collection_name.find().pretty()
Retrieving Documents
Introduction to MongoDB 22
Retrieving Documents with Filters or
Criteria
Introduction to MongoDB 23
Update Documents
Introduction to MongoDB 24
 There are 2 ways to update documents:
1. db.collection_name.updateOne()
2. db.collection_name.updateMany()
Update Documents
Introduction to MongoDB 25
Delete Documents
Introduction to MongoDB 26
 There are 2 ways to delete documents:
1. db.collection_name.deleteOne()
2. db.collection_name.deleteMany()
MongoDB Compass & MongoDB Atlas
Introduction to MongoDB 27
 MongoDB Compass is a powerful GUI for querying, aggregating, and analyzing your
MongoDB data in a visual environment. It is free to use and can be run on macOS,
Windows, and Linux.
 Installation link: MongoDB Compass Download | MongoDB
 MongoDB Atlas is a multi-cloud database service by the same people that build MongoDB.
It makes easy to deploy and manage databases on-demand when and where you need
them.
 Get Started with Atlas — MongoDB Atlas
References
Introduction to MongoDB 28
 MongoDB Documentation
 MongoDB - OneCompiler - Write, run and share MongoDB code online
 Online mongoDB Terminal - practice mongoDB online (jdoodle.com)
 MongoDB Exercises, Practice, Solution - w3resource
Thank you

Introduction to MongoDB.pptx

  • 1.
  • 2.
    Agenda Presentation Title Introduction toMongoDB 2  What is NoSQL?  Types of NoSQL  SQL Vs NoSQL  When to use NoSQL?  What is MongoDB?  Features of MongoDB  MongoDB Data types  Who’s using MongoDB?  MongoDB terms  MongoDB Installation  Some MongoDB commands  MongoDB Compass & MongoDB Atlas  References
  • 3.
    What is NoSQLDatabase? Introduction to MongoDB 3  The term “NoSQL database” refer to any “Non-relational” or “Not only SQL” databases provides a mechanism for storage and retrieval of data in a format 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.  Flexible schema i.e., no predefined or rigid schema.  It avoids joins and is easy to scale.
  • 4.
    Types of NoSQLDatabase Introduction to MongoDB 4 NoSQL Databases are mainly categorized into four types: Key-value pair, Column-oriented, Graph-based & Document-oriented.
  • 5.
    SQL Vs NoSQL Introductionto MongoDB 5 SQL NoSQL SQL databases are primarily called RDBMS or Relational Databases. NoSQL databases are primarily called as Non-relational or distributed database. SQL databases are table-based databases. NoSQL databases can be document based, key-value pairs, graph databases. Vertical Scalability Horizontal Scalability Fixed or Predefined schema. Flexible schema. Not suitable for hierarchical data storage. Suitable for hierarchical data storage. Oracle, MySQL, Microsoft SQL Server, and PostgreSQL. Document: MongoDB and CouchDB, Key-value: Redis and DynamoDB, Column-based: Cassandra and HBase, Graph: Neo4j and Amazon Neptune.
  • 6.
    When to useNoSQL? Introduction to MongoDB 6 1. When a huge amount of data needs to be stored and retrieved. 2. The relationship between the data you store is not that important 3. The data changes over time and is not structured. 4. Constraints and Joins support is not required at database level. 5. The data is growing continuously, and you need to scale the database regularly to handle the data.
  • 7.
    What is MongoDB? Introductionto MongoDB 7  Most popular NoSQL database.  Open-source document-oriented database.  Its scale-out architecture allows you to meet the increasing demand for your system by adding more nodes to share the load.  MongoDB uses BSON (Binary JSON) to query database.  Stores data in the form of BSON documents.
  • 8.
    Features of MongoDB Introductionto MongoDB 8  Indexing: Efficient search & data processing in very less time.  Scalability: MongoDB scales horizontally using sharding (partitioning data across various servers). Also, new machines can be added to a running database.  Replication & High Availability: Multiple copies of data is replicated on different servers which protects the database from hardware failures. If one server goes down, the data can be retrieved easily from other active servers which also had the data stored on them.  Load balancing: It has an automatic load balancing configuration because of data placed in shards.  Aggregation: Aggregation operations process data records and return the computed results. It is like the GROUPBY clause in SQL. A few aggregation expressions are sum, avg, min, max, etc.  Languages supported: The list of supported languages includes Node.js, C, C++, C#, Go, Java, Perl, PHP, Python, Ruby, Rust, Scala, and Swift.
  • 9.
  • 10.
    Who’s is usingMongoDB? Introduction to MongoDB 10 MongoDB has been adopted as backend software by a few major websites and services including Toyota, Cisco, Shutterfly, Adobe, Ericsson, Craigslist, eBay, and Foursquare.
  • 11.
    MongoDB Terms Introduction toMongoDB 11  Databases: A database stores one or more collections of documents.  Collections: MongoDB stores documents in collections. Collections are analogous to tables in relational databases.  Documents: MongoDB stores data records as BSON documents & similar to JSON objects. It is analogous to row in relational databases. These are composed of field-and-value pairs and have the following structure: { field1: value1, field2: value2, field3: value3, ... fieldN: valueN }  Fields Names: These are strings analogous to column in relational databases.
  • 12.
  • 13.
    SQL Vs MongoDBTerms Introduction to MongoDB 13
  • 14.
    MongoDB Installation Introduction toMongoDB 14  MongoDB is available in two server editions: Community and Enterprise.  Community edition is free & Enterprise edition is a paid version and has some advanced features.  Installation links: Install MongoDB — MongoDB Manual Community: Try MongoDB Community Edition | MongoDB Enterprise: Try MongoDB Enterprise Advanced | MongoDB
  • 15.
    Create Database Introduction toMongoDB 15 The use Database_name command makes a new database in the system if it does not exist, if the database exists it uses that database. For example, use mydb. Now your database is ready of name mydb.
  • 16.
    List all databases Introductionto MongoDB 16 To list down all the databases, use the command below: show dbs This command lists down all the databases and their size on the disk. mydb database is not created until you save a document in it.
  • 17.
    Create Collection Introduction toMongoDB 17 To create collection, use the command below: db.createCollection(name, options) name is name of collection to be created. Options is a document and is used to specify configuration of collection such as capped, autoIndexId, size.
  • 18.
    List all Collections Introductionto MongoDB 18 To see all collections in a database, use the command below: show collections
  • 19.
    Drop Database &Collection Introduction to MongoDB 19  Use the following command to delete a database: db.dropDatabase()  Use the following command to delete a collection: db.collection_name.drop()
  • 20.
    Create Documents Introduction toMongoDB 20 Two methods insert or create documents in collection: 1. db.collection_name.insertOne() 2. db.collection_name.insertMany()
  • 21.
    Retrieving Documents Introduction toMongoDB 21  Use the below command to retrieve documents: db.collection_name.find()  For a proper formatted output, use the below command: pretty() with find(). db.collection_name.find().pretty()
  • 22.
  • 23.
    Retrieving Documents withFilters or Criteria Introduction to MongoDB 23
  • 24.
    Update Documents Introduction toMongoDB 24  There are 2 ways to update documents: 1. db.collection_name.updateOne() 2. db.collection_name.updateMany()
  • 25.
  • 26.
    Delete Documents Introduction toMongoDB 26  There are 2 ways to delete documents: 1. db.collection_name.deleteOne() 2. db.collection_name.deleteMany()
  • 27.
    MongoDB Compass &MongoDB Atlas Introduction to MongoDB 27  MongoDB Compass is a powerful GUI for querying, aggregating, and analyzing your MongoDB data in a visual environment. It is free to use and can be run on macOS, Windows, and Linux.  Installation link: MongoDB Compass Download | MongoDB  MongoDB Atlas is a multi-cloud database service by the same people that build MongoDB. It makes easy to deploy and manage databases on-demand when and where you need them.  Get Started with Atlas — MongoDB Atlas
  • 28.
    References Introduction to MongoDB28  MongoDB Documentation  MongoDB - OneCompiler - Write, run and share MongoDB code online  Online mongoDB Terminal - practice mongoDB online (jdoodle.com)  MongoDB Exercises, Practice, Solution - w3resource
  • 29.