EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MongoDB Tutorial MongoDB Features
Secondary Sidebar
MongoDB Tutorial
  • Basics
    • What is MongoDB
    • How To Install MongoDB
    • MongoDB Tools
    • MongoDB GUI Tools
    • MongoDB Versions
    • MongoDB Commands
    • Advantages of MongoDB
    • MongoDB Features
    • Is MongoDB NoSQL
    • Is MongoDB Open Source
    • Build Web Applications using MongoDB
    • MongoDB Data Types
    • MongoDB Administration
    • Data Modeling in MongoDB
    • MongoDB vs Elasticsearch
    • MariaDB vs MongoDB
    • Firebase vs MongoDB
  • Commands
    • Mongodb updateMany
    • MongoDB Aggregation
    • Mongodb unwind
    • Mongodb where
    • MongoDB BSON
    • MongoDB Filter
    • Mongodb Match
    • MongoDB sort by date
    • MongoDB Limit()
    • MongoDB Atlas Login
    • MongoDB Relational Database
    • MongoDB count
    • MongoDB Aggregate
    • MongoDB Distinct
    • MongoDB Unique
    • MongoDB find
    • MongoDB findOne()
    • MongoDB insert
    • MongoDB Delete
    • MongoDB Update
    • Lookup in MongoDB
    • order by in MongoDB
    • MongoDB $regex
    • MongoDB $elemMatch
    • MongoDB ObjectId()
    • MongoDB Skip()
    • MongoDB findAndModify
    • Mongodb findOneAndUpdate
    • MongoDB Date Query
    • MongoDB Timestamp
    • MongoDB sort()
    • MongoDB group by
    • MongoDB Join
  • Advanced
    • MongoDB Array
    • PostgreSQL ARRAY_AGG()
    • Indexes in MongoDB
    • MongoDB create Index
    • MongoDB Collection
    • MongoDB List Collections
    • MongoDB Capped Collections
    • MongoDB Delete Collection
    • Mongodb show collections
    • MongoDB Auto Increment
    • MongoDB Triggers
    • MongoDB Projection
    • Replication in MongoDB
    • MongoDB Database
    • Mongo DB Create Database
    • MongoDB Compass
    • MongoDB Users
    • MongoDB Authentication
    • MongoDB GridFS
    • MongoDB Relationships
    • MongoDB MapReduce
    • MongoDB Geospatial
    • MongoDB Monitoring
    • Backup in MongoDB
    • MongoDB Sharding
    • MongoDB Java Drivers
    • MongoDB Import
    • Mongo Database Interview Questions
    • MongoDB Join Two Collections
    • MongoDB Group by Multiple Fields
    • MongoDB Pagination
    • MongoDB Replica Set
    • MongoDB Bulk Update
    • MongoDB greater than
    • MongoDB Encryption
    • MongoDB find in array
    • MongoDB like query
    • Mongodb shell
    • MongoDB port
    • MongoDB Query Operators
    • MongoDB Web Interface
    • MongoDB Query Array
    • MongoDB Transactions
    • MongoDB Not In
    • MongoDB not null
    • MongoDB npm
    • MongoDB Remove

MongoDB Features

By Sulaksh MoreSulaksh More

MongoDB Features

Introduction to MongoDB Features

MongoDB, being one of the most widely used NoSQL databases, provides a wide range of features and functionalities. These features are the reason why MongoDB is easy to use and adapted by major companies. We will learn about these features, with proper explanation and syntax, and example queries wherever required. MongoDB is a Document-based, Cross-Platform Database Program. It implements JSON like documents. Latest Stable version is, 4.2.5, released on 26th March 2020.

Below is a simple query returning the list of collections in the Database.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Code:

show dbs

show DBS will list every collection or table present in the DB.

MongoDB Features1

Data is stored in the form of JSON Document in MongoDB’s Collection. Every collection has documented, and every document has multiple key-value pairs. The key “_id” is involuntary set default primary key and initially indexed.

MongoDB Features

Let us now define and understand each feature :

1. Ad Hoc Queries Support

Basically, when we are in the Database Design phase, we have no idea of what queries might be executed. So, when we say, MongoDB supports Ad Hoc Queries, it means that the MongoDB supports queries that were not known while establishing a structure for the database. This is an amazing feature that makes MongoDB stand out. Ad hoc queries function in a way to better the performance and are real-time.

2. Indexing

One of the most important features for a Database is Indexing, which results in improvements. We can index any field in MongoDB. Creating indexes helps in faster search results. Indexing is possible with any field or key, in a document.

Code:

db.test.getIndexes()

The above query will return every index that has been created for the “test” collection. Refer to the below-attached screenshot.

Output:

test collection

In the above sample, we see two indexes. The first one is created on “_id” which is default and created automatically. At the same time, the second one is with the “city” key.

3. Replication

Simply speaking, replication is a process of, distributing the data on multiple servers and keeping everything synchronized. Primary Node and Secondary Nodes are introduced here.

Working: Whenever a primary node, with the data, is down or experiences failure, the secondary node will be the working primary node, making it possible for the data to be available.

This feature is important regarding Data Storage and Backup, as it allows us to recover and restore, in case of failure in hardware or services. Thanks to this replication, that data is made available with multiple copies on different locations. Time is saved, and no operation is halted due to this amazing feature.

4. Schema-less Database

One of the most primarily discussed features of MongoDB is, it being Schemaless. Meaning that there can be multiple documents in a collection, with different keys, and these keys might not be found in other documents. This is the major reason behind MongoDB’s flexibility, with data.

We can have multiple documents or records in a single, same collection, but with different key values pairs. Check the below-attached screenshot for reference.

Code:

db.test.find().pretty()

Output:

MongoDB Features3

In the above example, you can see we have two documents. Both documents have slightly different keys. In the second record, we don’t have the city key, and yet it does not affect. This is made possible with a schema-less feature.

5. Document Oriented

Being Document Oriented is a great feature that helps MongoDB stand out among others. We have tables and rows columns structure for SQL, we have fields in key values pair, with MongoDB.

Code:

db.educba.find().pretty().limit(1)

Output:

key values pair

In the above Document, we have four key values, where _id is default and set automatically—this the basic structure of a document-based database.

6. Aggregation Pipeline

Aggregation Framework is one of the most efficient features offered by MongoDB. Simply speaking it is a process of creating a pipeline of multiple operations and getting a final result, filtered.

Code:

db.fun.aggregate([{$match: {"City":"Pune"}},{$sort: {_id:-1}}])

The above query will return documents that have Pune as their City, and it will print the sorted result. Refer the below-attached screenshot.

Output:

sorted result

Aggregation pipelines can be created as per needs. The end result must be thought carefully while building the pipeline.

7. GridFS

When a file exceeds the BSON document limit of 16 MB, it is divided into multiple small chunks and stored separately in various documents. These chunks have a size of 255KB, excluding the last chunk. GridFS, which stands for Grid File System, use two separate collections. One collection is used to store the larger file’s chunks, while the second collection is used to store the metadata. When we execute a query for this file, the GridFS will collect and return all the chunks together. GridFS also implements the Indexing, which allows the query execution for returning the file easier.

8. Sharding

When we are encountered with large datasets, we can implement the Sharding of Data. Meaning, the large datasets are split and shared across multiple machines. The massive data can cause unexpected problems, but the implementation of sharding can be useful. Sharding is the process of database partitioning and spreading across multiple machines, while the replication is the process of making multiple copies of the database. The data is distributed over multiple collections, and these collections are known as “Shards”.

9. High Performance

MongoDB is open-source, is one the highest performing database. With the implementation of replication and indexing, query execution and data fetching are faster. With developing multiple applications, the need to check the performance is mandatory. Database Profiling, which collects the complete data for every operation that is executed against the MongoDB instance. The output provided by the DB Profiler can help us understand the queries and operations that are being inefficient.

Conclusion

Document oriented and schema-less structure makes the MongoDB one of the preferable choice. Many other features like Aggregation pipeline, Sharding, Replication, etc. help the database query results faster with better performance. Load Balancing is done with these features results in better performance. All these features make the MongoDB one of the better choice for Big Data Application and Real-Time Applications.

Recommended Articles

This is a guide to MongoDB Features. Here we discuss an introduction to MongoDB Features, top 10 features with explanation in detail. You can also go through our other related articles to learn more –

  1. Advantages of MongoDB
  2. MongoDB GUI Tools
  3. MongoDB Tools
  4. MongoDB Alternatives
Popular Course in this category
MongoDB Training Program (4 Courses, 2 Projects)
  4 Online Courses |  2 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle Training (17 Courses, 8+ Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
SQL Training Program (10 Courses, 8+ Projects)4.7
Oracle DBA Database Management System Training (2 Courses)4.7
MS SQL Training (16 Courses, 11+ Projects)4.7
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more