MongoDB: A Complete Guide
MongoDB

What is MongoDB?

The most popular document database for modern applications

6-min readUpdated Aug 2026

MongoDB in 60 seconds

WHAT IT IS

A source-available document database that stores data as flexible BSON documents instead of rigid relational tables.

WHY IT'S USED

Teams pick it when the schema changes often and they want a JSON-native store with built-in sharding and replication.

STRENGTHS
  • +Flexible document model that fits nested JSON without upfront schema design
  • +Horizontal sharding and replica sets ship in the free community edition
  • +Aggregation pipeline handles complex analytics without a separate SQL engine
LIMITATIONS
  • Joins across collections are limited and awkward compared to relational SQL
  • SSPL license blocks major cloud providers from offering managed MongoDB
  • Working set has to fit in RAM for good performance under real workloads
BEST KNOWN FOR
Content management platformsReal-time analyticsIoT and mobile backendsProduct catalogsUser profiles and personalization
Jump to at a glance, how it works, or quick start for the full picture on MongoDB.

At a glance

CategoryDocument
First released2009
Latest release8.3 (May 2026)
LicenseSSPL
Written inC++, JavaScript
Runs onLinux, Macos, Windows
DeploymentSelf-hosted, Managed, Serverless
Wire protocolmongodb
Query dialectmql
Consistencytunable
ACID supportnative
JSON supportnative
Full-text searchnative
Vector supportnative
HA modelraft
Managed bymongodb-atlas

What is MongoDB?

MongoDB is a document database that stores data as JSON-like documents called BSON, a binary superset of JSON with extra types like ObjectId, dates, and 128-bit decimals. Instead of splitting related data across rows in different tables, you keep it together in a single document. That maps naturally to the objects an application already works with, so an order and its line items can live in one place, ready to read in a single query.

The engine started in 2007 at 10gen, a small ad-tech company that needed a database that could scale writes across cheap commodity servers. 10gen open-sourced it in 2009, dropped the ad-tech work to focus on the database, and renamed to MongoDB, Inc. The company went public in 2017. In 2018 it switched the server license from AGPL to the Server Side Public License, or SSPL, which the OSI does not accept as open source. That change kept AWS, Google, and other cloud providers from offering hosted MongoDB directly.

MongoDB became the default document database of the 2010s. Adobe, eBay, Forbes, Electronic Arts, Toyota, and Coinbase all run it in production. Atlas, the company's own managed service, is available on AWS, Azure, and GCP, and now generates most of MongoDB's revenue. On DB-Engines it consistently ranks as the most popular NoSQL database by a wide margin.

How MongoDB works

MongoDB is a client-server database. The mongod process listens on TCP port 27017 by default and speaks a binary wire protocol built on BSON. Drivers exist for most languages, and every driver knows how to route reads to secondaries, retry on failovers, and pool connections. Unlike Postgres, MongoDB uses a single multi-threaded process, so a busy server does not fork thousands of backend processes and does not need an external pooler.

Queries take one of two shapes. The find command runs a predicate against a collection and returns matching documents, using indexes when available. The aggregation pipeline chains stages like $match, $group, $lookup, and $project into a single query that can do joins, transformations, and analytics inside the server. A query planner picks the best plan based on collection statistics and cached winners from earlier runs.

Storage is handled by WiredTiger, a document-level MVCC engine that compresses on disk with Snappy or Zstd. Durability comes from a write-ahead journal. High availability lives in the replica set model, where a primary and two or more secondaries elect a new primary through Raft when the current one fails. Horizontal scale comes from sharding, which splits a collection across nodes by a shard key and lets a query router called mongos fan reads out to the right shards.

Key concepts

Documents and BSON

MongoDB stores data as BSON documents, a binary format that extends JSON with types like ObjectId, ISODate, and 128-bit Decimal. Each document is up to 16 MB and can hold nested objects and arrays. Documents skip the table-and-row rewrite most apps do at the ORM layer, so what you store looks like what you read.

Collections and databases

A collection is a bucket of documents, roughly analogous to a table in SQL. Collections live inside databases, and a single mongod can host many of them at once. They do not enforce a schema by default, though you can attach a JSON Schema validator to reject documents that do not match the shape you expect.

Indexes

MongoDB supports B-tree indexes on any field, including fields nested inside subdocuments and arrays. On top of those it ships compound, text, geospatial 2dsphere, TTL, wildcard, and vector search indexes. An index can cover fields the app only reaches through a nested path, which is normal for document data.

Aggregation pipeline

Instead of SQL, MongoDB runs analytics through a pipeline of stages. Each stage transforms the documents flowing through it: $match filters, $group aggregates, $lookup joins another collection, $project reshapes, and $unwind flattens arrays. The whole pipeline runs inside the server, close to the indexes.

Replica sets

Every production MongoDB runs as a replica set: a primary that takes writes and secondaries that stream the oplog and apply it in order. If the primary fails, a Raft election picks a new one within seconds. Reads can be routed to the secondaries, so read-heavy apps scale their reads without much extra work.

Sharding

For datasets bigger than a single machine, MongoDB shards a collection across nodes by a shard key. A mongos router sits in front and directs each query to the shards that hold the matching data. The shard key is the most consequential choice in a cluster, since a poor one causes hot chunks and lopsided load.

MongoDB by the numbers

Live GitHub adoption, updated daily

GitHub stars
28.5k
+39 in 30d
Forks
5.8k
Weekly growth
+8
stars in the last 7 days
Last commit
today
Aug 2026

Who uses MongoDB

A handful of the companies running it in production

AdobeeBayForbesElectronic ArtsToyotaCoinbase

When to use MongoDB

Best for

Content and catalog data with variable shape

Products, articles, and user profiles each carry different fields. Documents let you store exactly what an item has, instead of forcing every row into the one fixed schema a table demands.

Real-time analytics and event streams

The aggregation pipeline runs multi-stage analytics inside the database, and change streams push updates to subscribers as they happen, so dashboards stay current without a second pipeline.

Mobile and IoT backends

Small documents map cleanly onto the objects an app already uses, drivers exist for every mobile language, and sharding scales writes across many devices with no redesign of the schema.

Vector search inside operational data

Atlas Vector Search keeps embeddings and their metadata in the same collection as your application data, so retrieval-augmented generation reads from one database at query time, not two.

Not ideal for

Highly relational data with strict joins

MongoDB has $lookup, but a schema with many foreign keys and cross-table constraints runs faster and cleaner on Postgres or MySQL, where multi-way joins are the native operation, not an add-on.

Analytical warehousing at TB scale

ClickHouse, BigQuery, and Snowflake are built for scan-heavy analytics over billions of rows, and beat it by an order of magnitude there. MongoDB can run the query, but it is the wrong tool.

Cache-tier latency in the microsecond range

MongoDB serves reads in the low single-digit milliseconds. If you need sub-millisecond reads for a session store or rate limiter, an in-memory store like Redis or Memcached wins on the same box.

Workloads that must stay strictly open source

MongoDB moved from the AGPL to the SSPL in 2018, which the OSI does not accept as open source. If your policy needs an OSI-approved license, use Postgres or the compatible FerretDB fork instead.

MongoDB vs alternatives

Head-to-head specs against the top 5 alternatives

MongoDB vs PostgreSQL
MongoDB
PostgreSQL
Identity
License
SSPL
PostgreSQL License
First released
2009
1996
Capabilities
Schema
Schema-less
Strict
ACID
Native
Native
JSON
Native
Native
HA model
Raft
Primary-standby
Ecosystem
Managed providers
1
9
ORM support
6
10
Use cases
Best for
Flexible-schema applications, content management, real-time analytics, and mobile/IoT backends
General-purpose OLTP, complex queries with advanced SQL, geospatial data with PostGIS, and applications requiring strong ACID compliance
Not ideal for
Highly relational data with complex joins or strict referential integrity requirements
Extreme write-heavy workloads at massive horizontal scale, simple key-value caching, or real-time streaming without extensions
MongoDB vs Amazon DynamoDB
MongoDB
Amazon DynamoDB
Identity
License
SSPL
Proprietary
First released
2009
2012
Capabilities
Schema
Schema-less
Schema-less
ACID
Native
Native
JSON
Native
Native
HA model
Raft
Multi-master
Ecosystem
Managed providers
1
1
ORM support
6
2
Use cases
Best for
Flexible-schema applications, content management, real-time analytics, and mobile/IoT backends
Serverless applications, high-throughput key-value access patterns, and globally distributed low-latency workloads
Not ideal for
Highly relational data with complex joins or strict referential integrity requirements
Complex relational queries, ad-hoc analytics, or workloads requiring flexible querying without predefined access patterns
MongoDB vs MySQL
MongoDB
MySQL
Identity
License
SSPL
GPLv2
First released
2009
1995
Capabilities
Schema
Schema-less
Strict
ACID
Native
Native
JSON
Native
Native
HA model
Raft
Multi-master
Ecosystem
Managed providers
1
8
ORM support
6
8
Use cases
Best for
Flexible-schema applications, content management, real-time analytics, and mobile/IoT backends
Web applications, SaaS platforms, and high-throughput OLTP workloads
Not ideal for
Highly relational data with complex joins or strict referential integrity requirements
Complex analytical queries or workloads requiring advanced SQL features like CTEs with recursive optimization
MongoDB vs Cassandra
MongoDB
Cassandra
Identity
License
SSPL
Apache-2.0
First released
2009
2008
Capabilities
Schema
Schema-less
Strict
ACID
Native
Compatible
JSON
Native
Native
HA model
Raft
Multi-master
Ecosystem
Managed providers
1
3
ORM support
6
2
Use cases
Best for
Flexible-schema applications, content management, real-time analytics, and mobile/IoT backends
High-availability, write-heavy workloads requiring linear scalability across multiple data centers and regions
Not ideal for
Highly relational data with complex joins or strict referential integrity requirements
Ad-hoc queries with complex joins, small-scale deployments, or workloads requiring strong ACID transactions
MongoDB vs Redis
MongoDB
Redis
Identity
License
SSPL
RSALv2 / SSPLv1 / AGPLv3 (triple-licensed)
First released
2009
2009
Capabilities
Schema
Schema-less
Schema-less
ACID
Native
Compatible
JSON
Native
Native
HA model
Raft
Primary-standby
Ecosystem
Managed providers
1
6
ORM support
6
4
Use cases
Best for
Flexible-schema applications, content management, real-time analytics, and mobile/IoT backends
High-performance caching, session management, real-time leaderboards, rate limiting, pub/sub messaging, and AI vector search
Not ideal for
Highly relational data with complex joins or strict referential integrity requirements
Complex relational queries, large datasets exceeding available memory, or workloads requiring strong multi-key ACID transactions

Quick start

Install MongoDB locally, connect with mongosh, and insert a first document. Under a minute if you have Docker.

Install with Docker (fastest)
docker run --name mongodb -p 27017:27017 -d mongo:8
Or install natively
# macOS
brew tap mongodb/brew && brew install mongodb-community@8
brew services start mongodb-community@8

# Ubuntu/Debian
sudo apt install -y mongodb-org && sudo systemctl start mongod
Connect with mongosh
mongosh mongodb://localhost:27017
Insert a document and query it
use myapp;

db.users.insertOne({
  email: "[email protected]",
  createdAt: new Date(),
});

db.users.find();

That is a working install. Drivers exist for every major language, and mongosh gives you a full JavaScript shell for ad-hoc work.

Frequently asked questions

What is MongoDB used for?
MongoDB is a general-purpose document database used for anything that benefits from a flexible JSON shape: content management, product catalogs, user profiles, real-time analytics, mobile backends, and IoT ingestion. Companies like Adobe, eBay, Forbes, Electronic Arts, Toyota, and Coinbase run it in production. It also increasingly serves as a vector store for AI apps thanks to Atlas Vector Search, which puts embeddings next to operational data in the same collection.
Is MongoDB a SQL or NoSQL database?
MongoDB is a NoSQL database, specifically a document database. It stores data as BSON documents (a binary extension of JSON) instead of rows in tables, and queries with a language called MQL rather than SQL. The aggregation pipeline handles the kind of grouping and joining that SQL uses GROUP BY and JOIN for. Some teams also access MongoDB with a SQL layer, like the BI Connector or Atlas SQL, when they need to plug into a BI tool that speaks SQL only.
Is MongoDB free?
MongoDB Community Edition is free to download, run, and use in production under the SSPL license, and Atlas has a permanent free tier for small clusters. Enterprise Advanced and paid Atlas plans cost money and add features like LDAP, encryption at rest with KMS integration, auditing, and larger clusters. The SSPL is source-available rather than open source, so cloud providers cannot offer hosted MongoDB directly without paying, but self-hosting is unrestricted.
Who owns and maintains MongoDB?
MongoDB is developed and owned by MongoDB, Inc., a public company (NASDAQ: MDB) headquartered in New York. The engine started at 10gen in 2007 and was open-sourced in 2009. Unlike PostgreSQL, which is community-run with no owning entity, MongoDB is a single-vendor product. That gives it a clear roadmap and a paid support path, but also means the license, pricing, and feature gating are decisions made inside one company.
Is MongoDB open source?
Not by the OSI's definition. Through 2018 MongoDB was licensed under the AGPL, which is OSI-approved. In October 2018 the company switched to the Server Side Public License (SSPL), which requires anyone offering MongoDB as a managed service to open-source their entire hosting stack. The OSI rejected the SSPL as non-free. The code is still on GitHub and free to self-host, so many teams treat it as effectively open source, but strict open-source policies would exclude it.

Skip the config files

Connect to MongoDB in 30 seconds. Browse tables, run queries, and edit rows visually, on localhost, self-hosted, or cloud.

Open MongoDB in 1bench