Audvik Labs

Learning about MongoDB


MongoDB is an open source NoSQL database management program. NoSQL is used as an alternative to traditional relational databases. NoSQL databases are quite useful for working with large sets of distributed data. MongoDB is a tool that can manage document-oriented information, store or retrieve information. 

MongoDB supports various forms of data. It is one of the many nonrelational database technologies that arose in the mid-2000s under the NoSQL banner — normally, for use in big data applications and other processing jobs involving data that doesn’t fit well in a rigid relational model. Instead of using tables and rows as in relational databases, the MongoDB architecture is made up of collections and documents. 

Organizations can use Mongo DB for its ad-hoc queries, indexing, load balancing, aggregation, server-side JavaScript execution and other features. 

How it works 

MongoDB makes use of records which are made up of documents that contain a data structure composed of field and value pairs. Documents are the basic unit of data in MongoDB. The documents are similar to JavaScript Object Notation, but use a variant called Binary JSON (BSON). The benefit of using BSON is that it accommodates more data types. The fields in these documents are similar to the columns in a relational database. Values contained can be a variety of data types, including other documents, arrays and arrays of documents, according to the MongoDB user manual. Documents will also incorporate a primary key as a unique identifier. 

Sets of documents are called collections, which function as the equivalent of relational database tables. Collections can contain any type of data, but the restriction is the data in a collection cannot be spread across different databases. 

The mongo shell is a standard component of the open source distributions of MongoDB. Once MongoDB is installed, users connect the mongo shell to their running MongoDB instances. The mongo shell acts as an interactive JavaScript interface to MongoDB, which allows users to query and update data, and conduct administrative operations. 

A binary representation of JSON-like documents is provided by the BSON document storage and data interchange format. Automatic sharding is another key feature that enables data in a MongoDB collection to be distributed across multiple systems for horizontal scalability, as data volumes and throughput requirements increase. 

The NoSQL DBMS uses a single master architecture for data consistency, with secondary databases that maintain copies of the primary database. Operations are automatically replicated to those secondary databases for automatic failover. 

Why MongoDB? 

There are four major reasons why MongoDB is being deployed more often. They are: 

1. Flexibility: 

MongoDB uses documents that can contain sub-documents in complex hierarchies making it expressive and flexible. MongoDB can map objects from any programming language, ensuring easy implementation and maintenance 

2. Flexible Query Model: 

The user can selectively index some parts of each document or a query based on regular expressions, ranges, or attribute values, and have as many properties per object as needed by the application layer. 

3. Native Aggregation: 

Native aggregation allows users to extract and transform data from the database. The data can either be loaded into a new format or exported to other data sources.  

4. Schema-less model: 

Applications get the power and responsibility to interpret different properties found in a collection’s documents. 

Salient Features of MongoDB 

1. General-Purpose Database:

MongoDB can serve diverse sets of data and multiple purposes within a single application.  

2. Flexible Schema Design: 

The document-oriented approach allows non-defined attributes to be modified on the fly. This is a key contrast between MongoDB and other relational databases.  

3. Load Balancing and Scalability: 

It is built to scale, both vertically and horizontally. Using the technique of sharding, an architect can achieve both write and read scalability. Data balancing occurs automatically and transparently to the user by the shard balancer. 

4. Aggregation Framework: 

MongoDB offers an Extract, Transform, Load (ETL) framework which eliminates the need for complex data pipelines. 

5. Native Replication: 

Data gets replicated across a replica set without a complicated setup. 

6. Security Features: 

Authentication and authorization are taken into account.  

7. JSON: 

JSON is widely used across for frontend and API communication. It only makes sense for the database to use the same protocol.  

8. MapReduce: 

MongoDB offers a great tool, MapReduce to build data pipelines. 

Conclusion : Working of MongoDB 

The entire database consists of collections. These collections hold multiple documents, and since MongoDB is schemaless, the documents in one collection need not be similar. All data is stored as BSON documents with the help of key-value pairs. At the backend, MongoDB converts JSON data into a binary format known as BSON. MongoDB also makes provision for nested data. This makes fetching data comparatively efficient. 

Leave a comment

Your email address will not be published. Required fields are marked *