MongoDB Introduction (Day 1)

Introduction 

 
These days, I am working on MongoDB databases. That's why I thought to write a series of articles on MongoDB. This is the first article in the new series. Today, I will provide a brief introduction to MongoDB.

MongoDB

MongoDB

MongoDB is a document-based, open-source database. MongoDB is a leading NoSQL database. It provides high performance, high availability, auto sharding, and automatic scaling. MongoDB database is written mainly in C++. Its drivers and client libraries are typically written in their respective languages, although some drivers use C extensions for better performance. MongoDB differs from relational databases because it is a schema-less database. Such databases usually have lower transaction safety but are faster in accessing data and scale compared to relational databases.

History of MongoDB

MongoDB was developed in October 2007 by a New York-based organization, 10gen, now called MongoDB Inc. It is written in C, C++, and JavaScript. MongoDB was initially developed as a Platform as a Service (PAAS). In 2009 MongoDB was introduced as an open-source database server. MongoDB provides backend services to many websites and to other services. For example, eBay, Foursquare, Viacom, Craigslist and the New York Times.

Document Database

Document Database

MongoDB stores data as documents. So it is a document-based database. A document is a data structure that stores the data in field and value pairs. The format of MongoDB documents are similar to JavaScript Object Notation (JSON). The values of a field may include a simple value, array and other documents. MongoDB uses BSON format to store the data into a document.

The following are the advantages of a document type database:
  • Documents written in JSON format is readable to humans, so it is easy to understand.
  • We can generate embedded documents and arrays that reduce the need for Joins.
  • Dynamic schema supports fluent polymorphism.

BSON

BSON

MongoDB represents JSON documents in a binary-encoded format called BSON behind the scenes. BSON extends the JSON model to provide additional data types and to be efficient for the encoding and decoding within various languages. It adds support for data types like date and binary that aren't supported in JSON.

The implementation of BSON in MongoDB has some benefits, for example:

  • It's very fast in execution
  • It's lightweight
  • It's easy to traverse
  • It supports embedding objects and arrays within other objects and arrays
  • It provides support for Index and Object matching against query expressions

Transaction Management in MongoDB

MongoDB doesn't support multiple document transactions. It only provides atomic operations on a single document. These atomic operations are sufficient to handle the problem that requires transaction management.

Basic Translation Terms/Concepts:
RDBMS vs MondoDB

Translation Terms

  • An RDBMS database is a set of tables, but in MongoDB, a database is a set of collections.
  • Instead of a table, we use a collection in MongoDB.
  • In an RDBMS, data is stored as rows, but MongoDB stores data as documents.
  • Instead of columns, we use key-value pairs in MongoDB.

Key Features of MongoDB

MongoDB is a document type of database that uses JSON format for the data store.

The following are some key features of MongoDB.

  • Dynamic Schema: MongoDB supports dynamic schemas. In other words, we need not define the schema before the insertion of data. We can change the schema of the database dynamically. A dynamic schema supports fluent polymorphism.

  • Embedded Data Model: MongoDB uses an embedded data model. In other words, we can define a document as a key/value pair in another document.

  • Use of Index: We can define an index on any attributes of a MongoDB records that increase the speed of data fetching.

  • Rich Query: MongoDB supports rich queries to fetch data from the database.

  • Automatic Scaling: MongoDB uses a Scaling Out approach. This is also known as Horizontal scaling. In the Scaling Out approach, data is distributed across clusters.

  • Data Sharding: MongoDB spreads data across servers without affecting the performance of the application. It removes the dependency on a single server. The database never goes offline. In other words, it provides 24/7 x 365 services.

  • Mirroring: We can set mirrors across a Local Area Network (LAN) and a Wide Area Network (WAN). That makes it easily scalable.

  • Supports Many Language: MongoDB supports many languages including C, C++, Ruby, C#, Perl, PHP, Python, Java, JavaScript, Erlang, and Haskell.

  • Replication: MongoDB supports data replication that has the data within a system geo-distributed, preferably using a non-interactive, reliable process.

  • Dynamic Query: MongoDB supports dynamic query for documents as a document-based query language that is nearly as powerful as, or more powerful than, SQL.

  • Mapping Not Required: Conversion or mapping of application objects to database objects isn't required.

  • MongoDB supports Java-Script for server-side execution. MongoDB uses JSON format for data storage and retrieval at the client-side. In other words, it allows a developer to use a single programming language for both client-side and server-side code.

  • MongoDB supports un-structured or semi-structured data.

  • Uses internal memory for storing the (windowed) working set, enabling faster access to data.

  • MongoDB is very easy to install and use.

Thanks for reading this article. In the next article, I will explain how to install MongoDB on your machine.

Author
Next » Install MongoDB on Windows (Day 2)