MongoDB

From Canonica AI

Overview

MongoDB is a source-available and cross-platform document-oriented database program. Classified as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc.

History

MongoDB was first introduced in 2007 by the software company 10gen, which was created by Dwight Merriman and Eliot Horowitz. The database was initially developed as a component of a planned platform as a service product, but the company shifted to an open source development model in 2009. MongoDB Inc. is currently the company behind the database's ongoing development.

A screenshot of MongoDB interface
A screenshot of MongoDB interface

Architecture

The MongoDB architecture is made up of collections and documents. Unlike a relational database where data is stored in tables, MongoDB's architecture is based on collections and documents. A collection is a grouping of MongoDB Documents and is equivalent to an RDBMS table. A collection exists within a single database and does not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection have a similar or related purpose.

Features

MongoDB has a number of features that support mission-critical applications. These include:

  • Ad hoc queries: MongoDB supports search by field, range queries, and regular expression searches. Queries can return specific fields of documents and also include user-defined JavaScript functions.
  • Indexing: Any field in a MongoDB document can be indexed (indices in MongoDB are conceptually similar to those in RDBMS systems). Secondary indices are also available.
  • Replication: MongoDB provides high availability with replica sets. A replica set consists of two or more copies of the data. Each replica set member may act in the role of primary or secondary replica at any time. The primary replica performs all writes and reads by default. Secondary replicas maintain a copy of the data of the primary using built-in replication.
  • Load balancing: MongoDB uses sharding to scale horizontally by splitting data across multiple MongoDB instances. MongoDB can run over multiple servers, balancing the load and/or duplicating data to keep the system up and running in case of hardware failure.
  • File storage: MongoDB can be used as a file system with load balancing and data replication features over multiple machines for storing files.
  • Aggregation: MapReduce can be used for batch processing of data and aggregation operations.
  • Server-side JavaScript execution: JavaScript can be used in queries, aggregation functions (such as MapReduce), and sent directly to the database to be executed.
  • Capped collections: MongoDB supports fixed-size collections called capped collections. This type of collection maintains insertion order and, once the specified size has been reached, behaves like a circular queue.

Usage

MongoDB is used by a number of high-profile companies and organizations, including MetLife, Craigslist, eBay, Foursquare, and The New York Times, among others. It is commonly used for mobile apps, content management, real-time analytics, and applications involving IoT.

Criticisms and Controversies

While MongoDB has been praised for its scalability and developer-friendly features, it has also faced criticism. Some of the most common criticisms include the lack of SQL-like joins (which can make querying more complex), and concerns about its efficiency and performance, particularly when dealing with larger databases.

See Also