MongoDB - Day 1 (Introduction To MongoDB)

These days I am working on MongoDB databases. So I thought to write a series of articles on MongoDB. This is the first article of the 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++ . It's 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 better than relational databases.

History of MongoDB

MongoDB was developed in October 2007 by a New York based organization 10gen that is now called MongoDB Inc. It is written is C , C++ and JavaScript. MongoDB is developed as a Platform as a Service (PAAS) initially. In 2009 MongoDB was introduced as an open-source database server. MongoDB provides backend services to many websites and to other services. For examle, 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 are written in JSON format that readable by 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, like:

  • Very fast in execution
  • Lightweight
  • Easy to traverse
  • Supports embedding objects and arrays within other objects and arrays
  • 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

  • A RDBMS database is a set of tables but in MondoDB a database is a set of collections.
  • Instead of a table we use a collection in MongoDB.
  • In a 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: MonogDB 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: MondoDb 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 query 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 clustors.

  • Data Sharding: MongoDB spreads data across servers without effecting the performance of the application. It removes the dependency on a single server. The database never becomes offline. In other words it provides 24 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 the data storage and retrieval at the client side, in other words 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 of data.

  • MongoDB is very easy in installation and use.

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