Full Stack UNIT 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

UNIT 3

MongoDB

SYLLABUS:
Understanding NoSQL and MongoDB – Building
MongoDB Environment – User accounts – Access
control – Administering databases – Managing
collections – Connecting to MongoDB from Node.js –
simple applications
Understanding NoSQL and MongoDB:
Is MongoDB NoSQL?

Yes, MongoDB is a NoSQL Database. MongoDB is an open-

source NoSQL database. MongoDB is a document-based database.

MongoDB is one of the leading NoSQL databases. A NoSQL database, a

non-relational database, can process structured, semi-structured, and

unstructured data.

What is MongoDB?

MongoDB is an open-source database management system (DBMS) that

uses a document-oriented database model. MongoDB is written in C++.

MongoDB supports various forms of data. MongoDB stores data in flat

files using their binary storage objects. Data storage is very compact and

efficient, perfect for high data volumes. MongoDB stores data in JSON-

like documents, making the database flexible and scalable.

MongoDB is a document-oriented database model. Each MongoDB

database contains collections and which in turn have documents. Each


document can be different and depends on the varying number of fields.

The model of each document will be different in size and content from

each other. The data model features allow storing arrays and complex

structures in a hierarchical relationship.


Developer(s) : MongoDB Inc.
Initial release : February 11, 2009

Stable release : 6.0.5 / 13 March 2023,2 months ago

Written in : C++, JavaScript, Python


Operating system : Windows Vista and later, Linux, OS X 10.7
and later, Solaris, FreeBSD
Characteristics of MongoDB:

Below are the characteristics of MongoDB:

 MongoDB is Schema-Less: MongoDB is a schema-less database which


flexible than traditional database tables. It is written in the language C++.
It has no schema to have many fields, content, and size different from
another document in the same collection.
 High Performance: MongoDB is an open-source database with high
performance. MongoDB is a high-availability and scalability database. It
supports faster query response because of features like indexing and
replication.
 MongoDB Indexing: Indexing is very important for improving the
performance of search queries. MongoDB uses indexing of datasets to
enhance query performances and searches. MongoDB indexing enhances
the performance for the faster search query. Document in a MongoDB
can be used for indexing using primary and secondary indices.
 File Storage: MongoDB can be used as a file system with load balancing
and data replication features over multiple machines for storing files.
 Replication: The feature of replication is to distribute data to multiple
nodes. It can have primary nodes and secondary nodes to replicate data.
Replication of data is done using master-slave architecture. MongoDB
provides a replication feature by distributing data across multiple
machines.
 Sharding: This process distributes data across multiple physical
partitions called shards due to sharding MongoDB automatic process load
balancing. We use sharding in cases where we need to work on larger
datasets.

What is NoSQL?

NoSQL is a new database management system breed that fundamentally

differs from relational database systems. NoSQL database is a highly

scalable and flexible database management system. NoSQL database


allows users to store and process unstructured and semi-structured data;

this feature is impossible in RDBMS tools. NoSQL is an approach to


database design that can accommodate a wide variety of data models,

including key-value, document, columnar and graph formats. NoSQL

systems don’t generally provide the same level of data consistency as

SQL databases. SQL databases have traditionally sacrificed scalability and

performance for ACID properties. NoSQL databases guarantee high

speed and scalability performance. NoSQL systems have the architecture


in such a way to operate at high speed and have wider flexibility towards

the developer side.

Characteristics of NoSQL
Below are the characteristics of NoSQL:
 Multi-Model: This feature of NoSQL databases makes them highly
flexible when handling data.
 Easily Scalable: This feature of NoSQL databases easily scales to adapt
to the massive volumes and complexity of cloud applications. This
scalability improves performance, allowing continuous availability and
high read/write speeds.
 Flexible: This feature of NoSQL databases allows you to process all
varieties of data. It can process structured, semi-structured, and
unstructured data. It works on many processors—NoSQL systems will
enable you to store your database on multiple processors and maintain
high-speed performance.
 Less Downtime: The elastic nature of NoSQL allows for the workload to
be spread across any number of servers automatically.

Can MongoDB Replace NoSQL?

We had limitations with Relational Databases for storing and processing

the large volume of social media and web data. NoSQL database was a
rescue for Big Data. NoSQL database allowed the programme1r to

execute the database with ease and efficiency. NoSQL database is of four

types. NoSQL can handle far more data in terms of volume and

complexity. NoSQL databases are either schema-free or have relaxed

schemas. MongoDB provides an aggregation feature for batch

processing to process your data efficiently. We use the Map Reduce

model for aggregation operations.


A MapReduce is a programming model composed of two procedures:
Map() and Reduce().Map() method performs filtering and sorting, while
Reduce() procedure performs a summary operation. MongoDB can run
over multiple servers. The data is duplicated to keep the system up and
keep its running condition in hardware failure. MongoDB is a schema-
less database. In MongoDB architecture – there are different documents
in one collection. The collection is schema-less to have other content,
fields, and size comparing another document in the same collection. The
features of NoSQL align with the offering of MongoDB. So, NoSQL
cannot replace MongoDB, or MongoDB cannot replace NoSQL.

Difference Between MongoDB and NoSQL:


 A MongoDB “database” is a top-level container that consists of one or
more collections, while NoSQL data stores provide a top-level namespace
or container for storing data.
 The document store data model is the basis of MongoDB, where
documents are stored in BSON format.
BSON format is a binary JSON format. NoSQL is an open-source
document database that provides high performance and scalability and
data modeling and managing massive data sets in an enterprise
application.
 MongoDB supports advanced features for searching any field, range of
queries, or regular expression, while NoSQL databases are more flexible
in data storage and processing.
 MongoDB uses the features of sharding to scale horizontally.
Simultaneously, NoSQL systems allow you to drag and drop your data
into a folder and query it without creating an entity-relational model.
Features of MongoDB –

 Schema-less Database : It is the great feature provided by the


MongoDB. A Schema-less database means one collection
can hold different types of documents in it. Or in other
words, in the MongoDB database, a single collection can
hold multiple documents and these documents may co nsist
of the different numbers of fields, content, and size. It is not
necessary that the one document is similar to another
document like in the relational databases.
 Document Oriented: In MongoDB, all the data stored in
the documents instead of tables like in RDBMS. In these
documents, the data is stored in fields(key-value pair)
instead of rows and columns which make the data much
more flexible in comparison to RDBMS. And each document
contains its unique object id.
 Indexing: In MongoDB database, every field in the
documents is indexed with primary and secondary indices
this makes easier and takes less time to get or search data
from the pool of the data. If the data is not indexed, then
database search each document with the specified query
which takes lots of time and not so efficient.
 Scalability: MongoDB provides horizontal scalability with
the help of sharding. Sharding means to distribute data on
multiple servers, here a large amount of data is partitioned
into data chunks using the shard key, and these data
chunks are evenly distributed across shards that reside
across many physical servers. It will also add new
machines to a running database.
 Replication: MongoDB provides high availability and
redundancy with the help of replication, it creates mul tiple
copies of the data and sends these copies to a different
server so that if one server fails, then the data is retrieved
from another server.
 Aggregation: It allows to perform operations on the
grouped data and get a single result or computed result. It
is similar to the SQL GROUPBY clause. It provides three
different aggregations i.e, aggregation pipeline, map -reduce
function, and single-purpose aggregation methods
 High Performance: The performance of MongoDB is very
high and data persistence as compared to another
database due to its features like scalability, indexing,
replication, etc.
Advantages of MongoDB :
 It is a schema-less NoSQL database. You need not to
design the schema of the database when you are working
with MongoDB.
 It does not support join operation.
 It provides great flexibility to the fields in the documents.
 It contains heterogeneous data.
 It provides high performance, availability, scalability.
 It supports Geospatial efficiently.
 It is a document oriented database and the data is stored in
BSON documents.
 It also supports multiple document ACID transition(string
from MongoDB 4.0).
 It does not require any SQL injection.
 It is easily integrated with Big Data Hadoop

Disadvantages of MongoDB :

 It uses high memory for data storage.


 You are not allowed to store more than 16MB data in the
documents.
 The nesting of data in BSON is also limited you are not
allowed to nest data more than 100 levels.
Building MongoDB Environment:

The process of setting up MongoDB in different operating systems is


also different, here various installation steps have been mentioned
and according to your convenience, you can select it and follow it.

Install MongoDB in Windows:

The website of MongoDB provides all the installation instructions, and


MongoDB is supported by Windows, Linux as well as Mac OS.

Once you visit the link (http://www.mongodb.org/downloads),

Once the download is complete, double click this setup file to install it. Follow the
steps:

1. Click Next.
2. Now, choose Complete to install MongoDB completely.
3. Then, select the radio button "Run services as Network service
user."

Once the installation is done completely, you need to start MongoDB


and to do so follow the process:

1. Open Command Prompt.


2. Type: C:\Program Files\MongoDB\Server\4.0\bin
3. Now type the command simply: mongod to run the server.

In this way, you can start your MongoDB database. Now, for running
MongoDB primary client system, you have to use the command:

C:\Program Files\MongoDB\Server\4.0\bin>mongo.exe
Datatypes in MongoDB:

MongoDB supports many datatypes. Some of them are −


 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.
 Boolean − This type is used to store a boolean (true/ false) value.
 Double − This type is used to store floating point values.
 Min/ Max keys − This type is used to compare a value against the
lowest and highest BSON elements.
 Arrays − This type is used to store arrays or list or multiple values
into one key.
 Timestamp − ctimestamp. This can be handy for recording when a
document has been modified or added.
 Object − This datatype is used for embedded documents.
 Null − This type is used to store a Null value.
 Symbol − This datatype is used identically to a string; however, it's
generally reserved for languages that use a specific symbol type.
 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.
 Object ID − This datatype is used to store the document’s ID.
 Binary data − This datatype is used to store binary data.
 Code − This datatype is used to store JavaScript code into the
document.
 Regular expression − This datatype is used to store regular
expression.

Create a User:

With access control enabled, users are required to identify themselves.


You have to grant a user one or more roles. A role grants a
user privileges to perform certain actions on MongoDB resources.

Each application and user of a MongoDB system should map to a


distinct user. This principle of access isolation facilitates access
revocation and ongoing user maintenance. To ensure a system of least
privilege, only grant the minimal set of privileges required to a user.

Prerequisites
To be able to create users, you need to:

 enable access control


 create a user administrator

For routine user creation, you must possess the following permissions:

 To create a new user in a database, you must have


the createUser action on that database resource.
 To grant roles to a user, you must have the grantRole action on the
role's database.

The userAdmin and userAdminAnyDatabase built-in roles


provide createUser and grantRole actions on their respective resources.

Procedure:
Connect and authenticate

Using mongosh , connect to your primary mongod or, in a sharded cluster, connect to
your mongos and authenticate as a user administrator or a user with the required
privileges:

Authenticate during Connection

Start mongosh with the -u <username>, -p, and the --


authenticationDatabase <database> command line options:

mongosh --port 27017 --authenticationDatabase \


"admin" -u "myUserAdmin" -p

Enter your password when prompted.


Create additional users for your deployment:

After authenticating as the user administrator, use the db.createUser() method to create
additional users. You can assign any built-in roles or user-defined roles to the users.

The following operation adds a user myTester to the test database who has
the readWrite role in the test database as well as the read role in the reporting database.

use test
db.createUser(

user: "myTester",

pwd: passwordPrompt(), // or cleartext password

roles: [ { role: "readWrite", db: "test" },

{ role: "read", db: "reporting" } ]

The database where you create the user (in this example, test) is that
user's authentication database. Although the user authenticates to this
database, the user can have roles in other databases. The user's
authentication database does not limit the user's privileges.

After creating the additional users, exit mongosh.

Connect to the instance and authenticate as myTester

After exiting mongosh as myUserAdmin , reconnect as myTester :

Authenticate during Connection:

Start mongosh with the -u <username>, -p, and the --


authenticationDatabase <database> command line options:

mongosh --port 27017 -u "myTester" \


--authenticationDatabase "test" -p

Enter the password for the user when prompted.

Insert a document as myTester

As the user myTester, you have privileges to perform read and write
operations in the test database (as well as perform read operations in
the reporting database). Once authenticated as myTester, insert a
document into a collection in the test database. For example, you can
perform the following insert operation in the test database:
db.foo.insertOne( { x: 1, y: 1 } )

Role-Based Access Control

MongoDB employs Role-Based Access Control (RBAC) to govern


access to a MongoDB system. A user is granted one or more roles that
determine the user's access to database resources and operations.
Outside of role assignments, the user has no access to the system.
Enable Access Control

MongoDB does not enable access control by default. You can enable
authorization using the --auth or the security.authorization setting.
Enabling internal authentication also enables client authorization.

Once access control is enabled, users must authenticate themselves.

Roles

A role grants privileges to perform the specified actions on resource.


Each privilege is either specified explicitly in the role or inherited from
another role or both.

Access

Roles never limit privileges. If a user has two roles, the role with the
greater access takes precedence.

For example, if you grant the read role on a database to a user that
already has the readWriteAnyDatabase role, the read grant
does not revoke write access on the database.

To revoke a role from a user, use the revokeRolesFromUser command.

Authentication Restrictions

Roles can impose authentication restrictions on users, requiring them to


connect from specified source and destination IP address ranges.
Privileges

A privilege consists of a specified resource and the actions permitted on


the resource.

A resource is a database, collection, set of collections, or the cluster. If


the resource is the cluster, the affiliated actions affect the state of the
system rather than a specific database or collection. For information on
the resource documents, see Resource Document.

An action specifies the operation allowed on the resource. For available


actions see Privilege Actions.

Inherited Privileges

A role can include one or more existing roles in its definition, in which
case the role inherits all the privileges of the included roles.

A role can inherit privileges from other roles in its database. A role
created on the admin database can inherit privileges from roles in any
database.

View Role's Privileges

You can view the privileges for a role by issuing the rolesInfo command
with the showPrivileges and showBuiltinRoles fields both set to true.

Users and Roles

You can assign roles to users during the user creation. You can also
update existing users to grant or revoke roles. For a full list of user
management methods, see User Management

A user assigned a role receives all the privileges of that role. A user can
have multiple roles. By assigning to the user roles in various databases,
a user created in one database can have permissions to act on other
databases.
NOTE:

The first user created in the database should be a user administrator


who has the privileges to manage other users. See Enable Access
Control.

Built-In Roles and User-Defined Roles

MongoDB provides built-in roles that provide set of privileges commonly


needed in a database system.

If these built-in-roles cannot provide the desired set of privileges,


MongoDB provides methods to create and modify user-defined roles.

LDAP Authorization

MongoDB Enterprise supports querying an LDAP server for the LDAP


groups the authenticated user is a member of. MongoDB maps the
Distinguished Names (DN) of each returned group to roles on
the admin database. MongoDB authorizes the user based on the
mapped roles and their associated privileges. See LDAP
Authorization for more information.

Administraion :
What is Administration in MongoDB?

The administration documentation addresses the ongoing operation and


maintenance of MongoDB instances and deployments. This
documentation includes both high level overviews of these concerns as
well as tutorials that cover specific procedures and processes for
operating MongoDB.

The core administration documents address strategies and practices used


in the operation of MongoDB systems and deployments.

 Operational Strategies –Higher level documentation of key


concepts for the operation and maintenance of MongoDB
deployments.

 MongoDB Backup Methods – Describes approaches and


considerations for backing up a MongoDB database.

 Monitoring for MongoDB – An overview of monitoring tools,


diagnostic strategies, and approaches to monitoring replica sets and
sharded clusters.

 Run-time Database Configuration – Outlines common MongoDB


configurations and examples of best-practice configurations for
common use cases.

 Data Management – Core documentation that addresses issues in


data management, organization, maintenance, and lifecycle
management.
 Data Center Awareness – Presents the MongoDB features that
allow application developers and database administrators to
configure their deployments to be more data center aware or allow
operational and location-based separation.

 Capped Collections – Capped collections provide a special type of


size-constrained collections that preserve insertion order and can
support high volume inserts.

Managing Collections :
MongoDB stores documents in collections. Collections are analogous to

tables in relational databases.

Create a Collection :

If a collection does not exist, MongoDB creates the collection when you first
store data for that collection.

db.myNewCollection2.insertOne( { x: 1 } )

db.myNewCollection3.createIndex( { y: 1 } )

Both the insertOne() and the createIndex() operations create their


respective collection if they do not already exist. Be sure that the collection
name follows MongoDB Naming Restrictions.

Explicit Creation :

MongoDB provides the db.createCollection() method to explicitly


create a collection with various options, such as setting the maximum size or
the documentation validation rules. If you are not specifying these options, you
do not need to explicitly create the collection since MongoDB creates new
collections when you first store data for the collections.

To modify these collection options, see collMod.

Document Validation :

By default, a collection does not require its documents to have the same
schema; i.e. the documents in a single collection do not need to have the
same set of fields and the data type for a field can differ across documents
within a collection.

Starting in MongoDB 3.2, however, you can enforce document validation


rules for a collection during update and insert operations. See Schema
Validation for details.
Modifying Document Structure :

To change the structure of the documents in a collection, such as add new


fields, remove existing fields, or change the field values to a new type, update
the documents to the new structure.

Unique Identifiers :

Collections are assigned an immutable UUID. The collection UUID remains


the same across all members of a replica set and shards in a sharded cluster.

To retrieve the UUID for a collection, run either the listCollections command or
the db.getCollectionInfos() method.
Connect to a MongoDB Database Using

Node.js :
Install Node.js :
First, make sure you have a supported version of Node.js installed. The current
version of MongoDB Node.js Driver requires Node 4.x or greater. See
the MongoDB Compatability docs for more information on which version of
Node.js is required for each version of the Node.js driver.

Install the MongoDB Node.js Driver


The MongoDB Node.js Driver allows you to easily interact with MongoDB
databases from within Node.js applications. You'll need the driver in order
to connect to your database and execute the queries described in this
Quick Start series.

If you don't have the MongoDB Node.js Driver installed, you can install it
with the following command.
npm install mongodb

At the time of writing, this installed version 3.6.4 of the driver. Running npm
list mongodb will display the currently installed driver version number.

Create a free MongoDB Atlas cluster and load the


sample data
Next, you'll need a MongoDB database. The easiest way to get started with
MongoDB is to use Atlas, MongoDB's fully-managed database-as-a-
service.

Head over to Atlas and create a new cluster in the free tier. At a high level,
a cluster is a set of nodes where copies of your database will be stored.
Once your tier is created, load the sample data. If you're not familiar with
how to create a new cluster and load the sample data, check out this video
tutorial from MongoDB Developer Advocate Maxime Beugnet.

Get started with an M0 cluster on Atlas today. It's free forever, and it's the
easiest way to try out the steps in this blog series.

Get your cluster’s connection info


The final step is to prep your cluster for connection.

In Atlas, navigate to your cluster and click CONNECT. The Cluster


Connection Wizard will appear.

The Wizard will prompt you to add your current IP address to the IP Access
List and create a MongoDB user if you haven't already done so. Be sure to
note the username and password you use for the new MongoDB user as
you'll need them in a later step.

Next, the Wizard will prompt you to choose a connection method.


Select Connect Your Application. When the Wizard prompts you to select
your driver version, select Node.js and 3.6 or later. Copy the provided
connection string.

Connect to your database from a Node.js application


Now that everything is set up, it’s time to code! Let’s write a Node.js script
that connects to your database and lists the databases in your cluster.

Import MongoClient
The MongoDB module exports MongoClient, and that’s what we’ll use to
connect to a MongoDB database. We can use an instance of MongoClient
to connect to a cluster, access the database in that cluster, and close the
connection to that cluster.
const {MongoClient} = require('mongodb');
Create our main function
Let’s create an asynchronous function named main() where we will connect
to our MongoDB cluster, call functions that query our database, and
disconnect from our cluster.
async function main() {
// we'll add code here soon
}

The first thing we need to do inside of main() is create a constant for our
connection URI. The connection URI is the connection string you copied in
Atlas in the previous section. When you paste the connection string, don't
forget to update <username> and <password> to be the credentials for the
user you created in the previous section. The connection string includes
a <dbname> placeholder. For these examples, we'll be using
the sample_airbnb database, so replace <dbname> with sample_airbnb.

Note: the username and password you provide in the connection string are
NOT the same as your Atlas credentials.
/**
* Connection URI. Update <username>, <password>, and <your-cluster-url> to
reflect your cluster.
* See https://docs.mongodb.com/ecosystem/drivers/node/ for more details
*/
const uri = "mongodb+srv://<username>:<password>@<your-cluster-url>/test?ret
ryWrites=true&w=majority";

Now that we have our URI, we can create an instance of MongoClient.


const client = new MongoClient(uri);

Note: When you run this code, you may see DeprecationWarnings around
the URL string parserand the Server Discover and Monitoring engine. If you
see these warnings, you can remove them by passing options to the
MongoClient. For example, you could instantiate MongoClient by calling new
MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true }).

See the Node.js MongoDB Driver API documentation for more information
on these options.
Now we're ready to use MongoClient to connect to our
cluster. client.connect() will return a promise. We will use
the await keyword when we call client.connect() to indicate that we should
block further execution until that operation has completed.
await client.connect();

Now we are ready to interact with our database. Let's build a function that
prints the names of the databases in this cluster. It's often useful to contain
this logic in well named functions in order to improve the readability of your
codebase. Throughout this series, we'll create new functions similar to the
function we're creating here as we learn how to write different types of
queries. For now, let's call a function named listDatabases().

await listDatabases(client);

Let’s wrap our calls to functions that interact with the database in
a try/catch statement so that we handle any unexpected errors.
try {
await client.connect();

await listDatabases(client);

} catch (e) {
console.error(e);
}

We want to be sure we close the connection to our cluster, so we’ll end


our try/catch with a finally statement.
finally {
await client.close();
}

Once we have our main() function written, we need to call it. Let’s send the
errors to the console.
main().catch(console.error);

Putting it all together, our main() function and our call to it will look
something like the following.
async function main(){
/**
* Connection URI. Update <username>, <password>, and <your-cluster-url>
to reflect your cluster.
* See https://docs.mongodb.com/ecosystem/drivers/node/ for more details
*/
const uri = "mongodb+srv://<username>:<password>@<your-cluster-url>/test
?retryWrites=true&w=majority";

const client = new MongoClient(uri);

try {
// Connect to the MongoDB cluster
await client.connect();

// Make the appropriate DB calls


await listDatabases(client);

} catch (e) {
console.error(e);
} finally {
await client.close();
}
}

main().catch(console.error);

List the databases in our cluster


In the previous section, we referenced the listDatabases() function. Let’s
implement it!

This function will retrieve a list of databases in our cluster and print the
results in the console.
async function listDatabases(client){
databasesList = await client.db().admin().listDatabases();

console.log("Databases:");
databasesList.databases.forEach(db => console.log(` - ${db.name}`));
};

Save Your File


You’ve been implementing a lot of code. Save your changes, and name
your file something like connection.js. To see a copy of the complete file,
visit the nodejs-quickstart GitHub repo.
Execute Your Node.js Script
Now you’re ready to test your code! Execute your script by running a
command like the following in your terminal: node connection.js

You will see output like the following:


Databases:
- sample_airbnb
- sample_geospatial
- sample_mflix
- sample_supplies
- sample_training
- sample_weatherdata
- admin
- local

Applications of MongoDB :

1. Web Applications :
MongoDB is widely used across various web applications as the primary data
store. One of the most popular web development stacks, the MEAN
stack employs MongoDB as the data store (MEAN stands for MongoDB,
ExpressJS, AngularJS, and NodeJS).

2. Big Data :
MongoDB also provides the ability to handle big data. Big Data refers to
massive data that is fast-changing, can be quickly accessed and highly available
for addressing needs efficiently. So, it can be used in applications where Big
Data is needed.

3. Demographic and Biometric Data :


MongoDB is one of the biggest biometrics databases in the world. It is used to
store a massive amount of demographic and biometric data. For example,
India’s Unique Identification project, Aadhar is using MongoDB as its database
to store a massive amount of demographic and biometric data of more than 1.2
billion Indians.

4. Synchronization :
MongoDB can easily handle complicated things that need synchronization with
each other entirely. So, it is mainly used in gaming applications. An example
gaming application developed using MongoDB as a database is “EA”. EA is a
world-famous gaming studio that is using MongoDB Database for its game
called FIFA Online 3.

5. Ecommerce :

For e-commerce websites and product data management and solutions, we can
use MongoDB to store information because it has a flexible schema well suited
for the job. They can also determine the pattern to handle interactions between
user’s shopping carts and inventory using “Inventory Management.”

MongoDB also has a report called “Category Hierarchy,” which will describe
the techniques to do interaction with category hierarchies in MongoDB .
Advantages of MongoDB :

 Flexible Database

 Sharding

 High Speed

 High Availability

 Scalability

 Easy Environment Setup


Disadvantages of MongoDB :

 Joins not Supported

 High Memory Usage


 Limited Data Size
 Limited Nesting

You might also like