Professional Documents
Culture Documents
you to condense and manipulate data stored in your collections. They enable you
to efficiently perform calculations and group results on even very large datasets.
operations you can perform on your data. Need to find the total number of
stock)
$min and $max for finding minimums and maximums (e.g., finding
SM22CO004
$count for getting document counts within groups (e.g., counting the
$first and $last to retrieve the first or last occurrence of a field value
customer)
particular field, you can categorize your data and analyze it from different
your collection. For instance, you can group products by category to see
identify your most frequent buyers. Additionally, you can group by multiple
fields to create even more granular analyses. Let's say you're running an
online store and want to see which product categories are most popular
product category and customer location, you can gain valuable insights into
● Used within the aggregation pipeline, a series of stages that process data.
SM22CO004
● Each stage takes the output of the previous stage and performs an
operation.
Benefits:
documents.
condense large collections of documents into sets of key metrics that reveal
patterns and trends within your data. This makes it significantly easier to
SM22CO004
identify outliers, track changes over time, and gain a deeper understanding
Complex data analysis with filtering and grouping: When combined with
example, you could filter your sales data to include only orders from a
product category to see which categories are driving the most sales in that
region.
In short, aggregation functions are like calculators for your MongoDB data,
allowing you to analyze and understand trends and patterns within your
collections.
Output:
SM22CO004
SM22CO004
EXPERIMENT NO. 9
INDEXING
Structure
· The address that is stored with the value work as a pointer to access
the document matching the query.
TYPES OF INDEXES
Default Index
This index do not allows clients to insert duplicate values for index.
SM22CO004
Example:
_id:ObjectID(“123gh456m”)
This index is created on the single field of the collection. It is used to retrieve the
data in ascending and descending order.
Syntax:
Example:
db.Student.createIndex(“sid”:1);
Compound Index:
Compound index does indexing on multiple field values store them in ascending
and descending order. the compound index will store the data of the field and
inside that it will store the data of another field, In other word compound index is
index where the single field value has multiple reference to the field . compound
index can have only one hashed single index . multiple hashed index will show
error.
Syntax:
db.<collection name>.createIndex({<field>:<type>,<field>:<type>});
Example:
db.students.createIndex({“Id”:1,”age”:-1}
Multikey Index
SM22CO004
Multikey index index the value stored in the array. When we index a field that
hold an array then mongodb will attomatical creates the index for every value in
the array. It is used to easily locate the document in the collection where the
array value matches the specified value. In mongodb we donot need to explicitly
specify multikey value mongodb will atomatically determines whether to create
multikey index if index field contains a array value.
Syntax:
db.<collection name>.createIndex({<array>:<type>,<array>:<type>});
Example:
db.students.createIndex({“hobbies”:1})
Text Index
MongoDB supports query operations that perform a text search of string content.
Text index allows us to find the string content in the specified collection. It can
include any field that contains string content or an array of string items. A
collection can contain at most one text index. We are allowed to use text index in
the compound index.
Syntax:
db.<collection name>.createIndex({<field>:”text”});
Example:
db.<collection name>.createIndex({“Name”:”text”});
SM22CO004
Compound Index :
Multikey Index :
SM22CO004
EXPERIMENT NO.4
provides an easy way to deploy, operate, and scale your MongoDB databases in
the cloud.
various cloud providers like Amazon Web Services (AWS), Google Cloud
Platform (GCP), and Microsoft Azure. This allows you to choose the cloud
provider that best suits your needs, whether you consider factors like cost,
permissions for users and roles, ensuring that only authorized users have
SM22CO004
access to specific data. Data encryption ensures that even if unauthorized
users manage to access your database, they will not be able to decrypt the
Ease of use: MongoDB Atlas is designed to be easy to use, even for those
can create, monitor, and manage your MongoDB clusters through a user-
applications.
If you're looking for a way to easily deploy and manage your MongoDB databases
in the cloud, MongoDB Atlas is a great option to consider. You can find more
This is the simplest and most recommended approach for most users,
SM22CO004
MongoDB Atlas is a fully-managed Database-as-a-Service (DaaS) offered by
MongoDB itself
your application.
Sign up for a free MongoDB Atlas account: [invalid URL removed] offers a
Choose your cloud provider and region: Atlas is multi-cloud, so you can
pick the provider that best suits your needs (AWS, GCP, Azure).
Configure your cluster: Define details like cluster name, instance size, and
this process.
This approach offers greater control over the configuration and resources
You'll be responsible for setting up, securing, scaling, and maintaining the
SM22CO004
Here's a general guideline for self-managed deployment (specific steps may
Choose your cloud provider: Select your preferred cloud platform (GCP,
provider.
Go for MongoDB Atlas if: You prioritize ease of use, scalability, and built-in
security. It's ideal for development, testing, and even production use cases
SM22CO004
cloud provider and require more customization. However, be prepared to
approach.
Output:
SM22CO004
Create a fiew Cluster
Cofifigure Cluster.
SM22CO004
Irfan123
SM22CO004
EXPERIMENT NO.10
create backups of your database in the form of binary BSON files. These backups
including:
● Standalone server
● Replica sets
● Sharded clusters
Here are some key points about mongodump for backing up your MongoDB
database:
creating database backups. With a single command, you can dump your
unwanted data.
SM22CO004
Portable Backups: The BSON files generated by mongodump are portable
Here are some resources to get you started with mongodump for backing up your
MongoDB database:
functionalities.
Mongodump is a command-line utility that comes with MongoDB and lets you
create backups of your database in a binary format called BSON. These backups
● Backup Types:
SM22CO004
Replica Sets: Backup data from a replica set deployment.
● Key Benefits:
backups.
customized backups.
restoration.
Mongorestore:
command-line utility used to restore your database from backups created with
mongodump.
SM22CO004
Here's a quick guide to using mongorestore:
Navigate: Open your terminal and use the cd command to navigate to the
● Replace [options] with any specific restore options you might need (e.g.,
● Replace [dump directory/file] with the path to your BSON dump file or
directory.
functionalities .
SM22CO004
versions are compatible with your MongoDB instance for a smooth
restoration process.
Output:
SM22CO004