0% found this document useful (0 votes)
14 views10 pages

Mongo DB-CRUD

The document provides an overview of NoSQL databases, particularly focusing on MongoDB, which is a document-oriented database known for its high performance, scalability, and flexible schema. It explains the types of NoSQL databases, the architecture of MongoDB, its key features, and advantages over traditional relational databases (RDBMS). Additionally, it outlines the CRUD operations in MongoDB, detailing how to create, read, update, and delete documents within collections.

Uploaded by

sangamiarjunan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views10 pages

Mongo DB-CRUD

The document provides an overview of NoSQL databases, particularly focusing on MongoDB, which is a document-oriented database known for its high performance, scalability, and flexible schema. It explains the types of NoSQL databases, the architecture of MongoDB, its key features, and advantages over traditional relational databases (RDBMS). Additionally, it outlines the CRUD operations in MongoDB, detailing how to create, read, update, and delete documents within collections.

Uploaded by

sangamiarjunan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

VEC – CSE IV Semester – II Year – 19IT205T – DBMS

Reference:https://www.cloudduggu.com/mongodb/sharding

NoSQL Database:
NoSQL databases are called "Not Only SQL" or "Non-relational" databases. NoSQL databases
store and retrieve data other than tabular relations such as relation databases.
NoSQL databases include MongoDB, HBase, and Cassandra.
There are following properties of NoSQL databases.
❖ Design Simplicity
❖ Horizontal Scaling
❖ High Availability

NoSQL databases come in a variety of types based on their data model. The main types are
document, key-value, wide-column, and graph. They provide flexible schemas and scale easily
with large amounts of data and high user loads.

Each NoSQL database has its own unique features. At a high level, many NoSQL databases have
the following features:
▪ Flexible schemas
▪ Horizontal scaling
▪ Fast queries due to the data model
▪ Ease of use for developers

Types of NoSQL databases


Over time, four major types of NoSQL databases emerged: document databases, key-value
databases, wide-column stores, and graph databases.

1. Document databases store data in documents similar to JSON (JavaScript Object


Notation) objects. Each document contains pairs of fields and values. The values can
typically be a variety of types including things like strings, numbers, booleans, arrays, or
objects.
2. Key-value databases are a simpler type of database where each item contains keys and
values.
3. Wide-column stores store data in tables, rows, and dynamic columns.
4. Graph databases store data in nodes and edges. Nodes typically store information about
people, places, and things, while edges store information about the relationships between
the nodes.

What is a Document Database?


A document database is a database that stores information in documents. Document
VEC – CSE IV Semester – II Year – 19IT205T – DBMS

databases offer a variety of advantages, including:

● An intuitive data model that is fast and easy for developers to work with.
● A flexible schema that allows for the data model to evolve as application needs change.
● The ability to horizontally scale out.

Because of these advantages, document databases are general-purpose databases that can be
used in a variety of use cases and industries.

Document databases are considered to be non-relational (or NoSQL) databases. Instead of


storing data in fixed rows and columns, document databases use flexible documents.
Document databases are the most popular alternative to tabular, relational databases.

MongoDB – Architecture

MongoDB was the startup of 10gen, which originated in 2007. Coming from the family
of Document stores, it is one of the typical NoSQL, schema-free databases with comparatively
high performance, scalability, and is rich in data processing functions. This open-source
database is written in C++ and makes use of dynamic schemas. The architecture
of MongoDB contains documents grouped into collections based on their structure. This
database makes use of BSON. BSON is the binary representation of JSON and supports
document storage and data interchange. In MongoDB, business subjects can be stored in a
VEC – CSE IV Semester – II Year – 19IT205T – DBMS

minimum number of documents, which can be indexed primarily or secondarily, without


breaking them into multiple relational ones.

Along with the above-mentioned capabilities of MongoDB, it also provides a large replica sets
collection where each set can contain more than one copy of data. In the replica sets, all primary
functions (read and write) are performed on the primary set while secondary sets are used in
case of failure of the former one. MongoDB incorporates sharding, which makes use of the
scaling process horizontally. The load balancing property of this document store database is
justified by the fact that it runs on multiple servers, thereby providing duplication of data and
balancing of the load. In return, it also provides backup during the hardware failure. It also
makes use of a grid file system which divides the particular file into different parts and stores
them separately.

The common features of MongoDB:

● The data model design reduces the need for joins and provides easy evolution of schema.
● High performance, as it contains neither join nor transactions which provide fast accessing
and hence performance is increased.
● High availability due to the incorporation of replica sets that are able to provide backup
during failures and also are highly robust.
● Ease in scalability.
● The sharding property of MongoDB enables it to perform fast and in an efficient manner in
the distributed functions. This is also possible since it supports horizontal scaling of data.
● Language is highly rich in the query. MongoDB has its own query language called Mongo
query language, which can replace SQL ones. Similarly, utility functions and map or reduce
can replace complicated aggregate functions.
VEC – CSE IV Semester – II Year – 19IT205T – DBMS

Figure 1: MongoDB Architecture

MongoDB is a cross-platform, document oriented database that provides, high


performance, high availability, and easy scalability. MongoDB works on concept of collection
and document.

Important Features of MongoDB


● Queries: It supports ad-hoc queries and document-based queries.
● Index Support: Any field in the document can be indexed.
● Replication: It supports Master–Slave replication. MongoDB uses native application to
maintain multiple copies of data. Preventing database downtime is one of the replica set’s
features as it has self-healing shard.
VEC – CSE IV Semester – II Year – 19IT205T – DBMS

● Multiple Servers: The database can run over multiple servers. Data is duplicated to
foolproof the system in the case of hardware failure.
● Auto-sharding: This process distributes data across multiple physical partitions called
shards. Due to sharding, MongoDB has an automatic load balancing feature.
● MapReduce: It supports MapReduce and flexible aggregation tools.
● Failure Handling: In MongoDB, it’s easy to cope with cases of failures. Huge numbers of
replicas give out increased protection and data availability against database downtime
like rack failures, multiple machine failures, and data center failures, or even network
partitions.
● GridFS: Without complicating your stack, any sizes of files can be stored. GridFS feature
divides files into smaller parts and stores them as separate documents.
● Schema-less Database: It is a schema-less database written in C++.
● Document-oriented Storage: It uses BSON format which is a JSON-like format.
● Procedures: MongoDB JavaScript works well as the database uses the language instead
of procedures.

Database: In simple words, it can be called the physical container for data. Each of the databases
has its own set of files on the file system with multiple databases existing on a single MongoDB
server.

Collection: A group of database documents can be called a collection. The RDBMS equivalent
to a collection is a table. The entire collection exists within a single database. There are no
schemas when it comes to collections. Inside the collection, various documents can have varied
fields, but mostly the documents within a collection are meant for the same purpose or for
serving the same end goal.
VEC – CSE IV Semester – II Year – 19IT205T – DBMS

Document: A set of key–value pairs can be designated as a document. Documents are associated
with dynamic schemas. The benefit of having dynamic schemas is that a document in a single
collection does not have to possess the same structure or fields. Also, the common fields in a
collection’s document can have varied types of data.

What makes it different from RDBMS?


You can directly compare the MongoDB NoSQL with the RDBMS and map the varied
terminologies in the two systems: The RDBMS table is a MongoDB collection, the column is a
field, the tuple/row is a document, and the table join is an embedded document. The typical
schema of a relational database shows the number of tables and the relationship between the
tables, but MongoDB does not follow the concept of relationship.
Go through the following table to understand how exactly an expert NoSQL database like
MongoDB differs from RDBMS. This blog has elucidated nine different comparisons between
the two.

MongoDB RDBMS
Document-oriented and non-relational Relational database
database
Document based Row based
Field based Column based
Collection based and key–value pair Table based
Gives JavaScript client for querying Doesn’t give JavaScript for querying
Relatively easy to setup Comparatively not that easy to setup
Unaffected by SQL injection Quite vulnerable to SQL injection
Has dynamic schema and ideal for Has predefined schema and not good for
hierarchical data storage hierarchical data storage
100 times faster and horizontally scalable By increasing RAM, vertical scaling can happen
through sharding

Why do you need MongoDB technology?


This technology overcame one of the biggest pitfalls of the traditional database systems, that is,
scalability. With the ever evolving needs of businesses, their database systems also needed to be
upgraded. MongoDB has exceptional scalability. It makes it easy to fetch the data and provides
continuous and automatic integration. Along with these benefits, there are multiple reasons why
you need MongoDB:
● No downtime while the application is being scaled
● Performs in-memory processing
VEC – CSE IV Semester – II Year – 19IT205T – DBMS

● Text search
● Graph processing
● Global replication
● Economical

RDBMS MongoDB

Database Database

Table Collection

Tuple/Row Document

column Field

Table Join Embedded Documents

Primary Key Primary Key (Default key _id provided by


MongoDB itself)

Database Server and Client

mysqld/Oracle mongod

mysql/sqlplus mongo

Advantages of MongoDB over RDBMS


● Schema less − MongoDB is a document database in which one collection holds different
documents. Number of fields, content and size of the document can differ from one document
to another.
● Structure of a single object is clear.
● No complex joins.
● Deep query-ability. MongoDB supports dynamic queries on documents using a document-
based query language that's nearly as powerful as SQL.
● Tuning.
● Ease of scale-out − MongoDB is easy to scale.
● Conversion/mapping of application objects to database objects not needed.
● Uses internal memory for storing the (windowed) working set, enabling faster access of data.
Why Use MongoDB?
● Document Oriented Storage − Data is stored in the form of JSON style documents.
● Index on any attribute
● Replication and high availability
● Auto-Sharding
● Rich queries
VEC – CSE IV Semester – II Year – 19IT205T – DBMS

● Fast in-place updates


● Professional support by MongoDB
● Big Data
● Content Management and Delivery
● Mobile and Social Infrastructure
● User Data Management
● Data Hub
To install MongoDB on Windows, first download the latest release of MongoDB
from https://www.mongodb.com/download-center.

MongoDB CRUD Operations


MongoDB is the Document-Based distributed database system that provides rich functionality to read
and write the data and these operations are achieved through MongoDB CRUD. The
MongoDB CRUD stands for CREATE, READ, UPDATE and DELETE which are used to perform the
operation such as create, update, read and delete on MongoDB Documents. Using these operations we
can easily interact with the database and perform various tasks.

The following figure represents the MongoDB CRUD operation.

The MongoDB CRUD concept has two operations, the first one is Read Operation and the second one
is Write operation. In Read Operation we have READ operation and in the Write operation we
have CREATE, UPDATE AND DELETE operation as mentioned in the below figure.
VEC – CSE IV Semester – II Year – 19IT205T – DBMS

Let us understand the MongoDB CRUD operations in the below section.

Create Operations in MongoDB


MongoDB Create Operations are used to create a new Document in a Collection. In case the Collection
is not present then it creates the Collection as well.

The below two methods are used for MongoDB Create Operations.

● db.collection_name.insertOne()
● db.collection_name.insertMany()

In the following example, we can see the Collection "users_detail" is created with the below data.

Read Operations in MongoDB


MongoDB Read Operations are used to read the Documents from the Collection.

MongoDB provides the following method to perform the Read Operations.

● db.collection_name.find()

The following is an example of Read Operations in MongoDB.

Update Operations in MongoDB


MongoDB Update Operations are used to modify existing Documents in the Collection.

The following methods are used to perform the Update Operations in MongoDB.
VEC – CSE IV Semester – II Year – 19IT205T – DBMS

● db.collection_name.updateOne()
● db.collection_name.updateMany()
● db.collection_name.replaceOne()

The following is an example of Update Operations in MongoDB.

Delete Operations in MongoDB


MongoDB Delete Operations are used to delete the Documents from the Collection.

The following methods are used to perform the Delete Operations in MongoDB.

● db.collection.deleteOne()
● db.collection.deleteMany()

The following is an example of Delete Operations in MongoDB.

You might also like