Introduction to MongoDB.pptx

9,187 views 29 slides May 11, 2023
Slide 1
Slide 1 of 29
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29

About This Presentation

This presentation gives a brief introduction to NoSQL & MongoDB.


Slide Content

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 When a huge amount of data needs to be stored and retrieved. The relationship between the data you store is not that important The data changes over time and is not structured. Constraints and Joins support is not required at database level. 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. O pen-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. Replicatio n & 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 sup ported: 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 . Co mmunity 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: s how 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: db.collection_name.insertOne () 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: db.collection_name.updateOne() db.collection_name.updateMany()

Update Documents Introduction to MongoDB 25

Delete Documents Introduction to MongoDB 26 There are 2 ways to delete documents: db.collection_name.deleteOne() 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