It is a distributed database at its core and provides high performance, scalability, and flexibility in querying and indexing data. It is easy to integrate with applications as the document model can map objects in the code. It provides drivers for major languages, and there is also a lot of professional support available. MongoDB stores it in an RDBMS-like structure.
Before going deep dive about MongoDB one needs to understand the following keys:
A database can be considered as a physical container for collections. Each database consisted of multiple databases with their file system. After specifying a URL connection one can create a database. It will be created as soon as it gets its content.
mydb = myclient[“mydatabase”]
name : “James”, age : 24, gender : “male” , interests : “tennis” }
A collection is simply a group of MongoDB documents, which is like an RDBMS table. A single collection can have different documents for varying different reasons. All the documents inside one single collection can have different schema as peruse. Using the database object, collections can be created as
mycol = mydb[“customers”]
A document is a place where the data is stored in JSON format, stored as a set of key-value pairs. They have a dynamic schema, all the documents have different sets of keys or fields, and common fields in a collection’s documents may hold different types of data.
Some benefits of using MongoDB
- Schemaless − MongoDB is a document database in which one collection holds different documents. Several fields, content, and size of the document can differ from one document to another.
- Document-oriented structure — It stores data in the form of documents like CloudFirestore in JSON format.
- Indexing — MongoDB makes use of primary and secondary indices which makes it easier to track the records
- Deep query-ability — MongoDB supports dynamic queries on documents using a document-based query language that’s nearly as powerful as SQL.
- Ease of scale-out − MongoDB is easy to scale.
- Scalability — It provides horizontal scalability with the help of sharding. Sharding refers to the distribution of data across different servers with the help of a 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: It provides high availability and redundancy with the help of replication as it creates multiple 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 quite similar to the SQL GROUP BY clause.
- High Performance: The performance of MongoDB is very high and data persistence as compared to other databases due to its features like scalability, indexing, replication, etc.
- GridFS: GridFS is the MongoDB specification for storing and retrieving large files such as images, audio files, video files, etc that stores its data in MongoDB collections. It has the capacity of storing files greater than its document size limit of 16MB and it divides a file into chunks and stores each chunk of data in a separate document, each of maximum size 255k.
- Ad-Hoc Queries: Ad-hoc queries are the queries not known while structuring the database. So, MongoDB provides ad-hoc query support which makes it so special in this case. Ad-hoc queries are updated in real-time, leading to an improvement in performance.
Getting Started with MongoDB
To get started go to https://www.mongodb.com/try/download/community and fill in the details and download it. After successful download, install the files.
For installation choose Rub Service as a Network Service User and run the installation.
Add the bin path in the Environment Variable.
Then simply go to the Command prompt and type in mongo, it will connect to the MongoDB server.
Advantages & Disadvantages
Advantages of MongoDB:
- It is a schemaless NoSQL database. There is no need to design the schema of the database
- It eliminates the need for complex join operations.
- It provides flexibility to the fields in the documents.
- It contains heterogeneous data.
- It provides high performance, availability, and scalability.
- It is a document-oriented database and the data is stored in JSON documents.
- It also supports multiple document ACID transitions.
- It does not require any SQL injection.
Disadvantages of MongoDB:
- It uses high memory for data storage.
- You are not allowed to store more than 16MB of data in the documents.
- There are concurrency issues that need to be taken care of.
- The nesting of data in JSON is also limited.
- Sometimes it offers higher latency reads.
Companies using MongoDB
From June to December in 2019, traffic continued to grow — setting new records month after month. Then came COVID-19. Like many high-profile publications, Forbes’ coverage of the pandemic has driven a further increase in traffic, reaching record traffic in May with more than 120 million unique visitors. Despite the turmoil and unprecedented digital traffic created, the development team continued to build, launch and test industry-leading features such as AI-assisted technology that recommend stories for its journalists and new data analysis tools to better understand reader behavior.
Forbes migrated its platform to Google Cloud and MongoDB Atlas. Results include:
- 58% faster build time for new products and fixes
- Accelerated release cycle by 4x
- The reduced total cost of ownership by 25%
- 28% increase in subscriptions from new newsletters
During the pandemic the cloud infrastructure has also helped the website scale to an extraordinary number of users and helped the team stay nimble, introducing and testing some new features.
Toyota — Toyota Material Handling Europe is building both the machines and the data platforms that will make this historic shift in manufacturing success. In an interview, the CEO discusses the shift from a monolithic codebase towards a microservices approach. The development teams could be more productive and the platform more user-friendly. Underpinning this change is MongoDB Atlas, MongoDB’s fully-managed, global cloud database service, which Toyota Material Handling runs on Microsoft Azure.
He also highlighted features that he liked about MongoDB: “The most beautiful part is the data model. Everything is a natural JSON document. So for the developers, it is easy, really easy for them to work with quickly. Spending time on building business value, rather than data modeling.”
Toyota Material Handling had eight evaluation criteria that were used to decide on which database platform they would use to make the switch:
- Performance — latency, scalable reads and writes to meet customer SLAs and accommodate significant growth in the future
- Automatic scalability, operations, and maintenance that enable developers to focus on applications, rather than backend database administration
- Security and compliance to safeguard highly sensitive business and personal data
- Data locality — able to host in Northwest Europe or West Europe in Microsoft Azure, therefore, ensuring close geographic proximity to factories for latency-sensitive operations
- Automatic backups and restore to provide fully managed data protection and disaster recovery
- Cloud agnostic, giving customers the freedom to run anywhere, on any platform
- Developer friendly database with a flexible data model so that developers can continuously integrate new application functionality and stay ahead of market demands
- Ecosystem for developer productivity, using proven best practices and widely available skills
Thank you for reading!!