Skip to main content

MongoDB

Pronunciation
MONG-goh-dee-bee
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/mongodb

In short

MongoDB is a document database that stores data as flexible JSON-like documents instead of table rows, so records in one collection can have different fields.

What is MongoDB?

MongoDB is a NoSQL document database first released in 2009 by the company now called MongoDB, Inc. Instead of tables, rows and columns, it stores documents in collections. A document is a JSON-like object, saved internally in a binary format called BSON, that can contain nested objects and arrays, so one document can hold a user together with their addresses and preferences.

Because there is no fixed schema, documents in the same collection can have different fields, and new fields can be added without a migration. Data that is read together is often stored together in one document, which avoids joins and makes typical reads fast. Indexes, an aggregation pipeline for grouping and transforming data, and multi-document ACID transactions are all built in.

MongoDB scales out across machines with sharding, which splits a collection by a shard key, and it keeps copies of data on several servers in a replica set, so a new primary is elected if one fails. MongoDB Atlas, the company's managed cloud service, is a common way to run it.

A common misconception is that a flexible schema means no design is needed. Without validation rules, data drifts into inconsistent shapes, and relationships between many collections can be awkward to query. MongoDB fits data that is naturally document-shaped; strongly relational data with many links between records often fits a relational database better.

Key takeaways

  • MongoDB stores JSON-like documents (BSON) in collections, not rows in tables.
  • Documents in one collection can have different fields.
  • Data read together is usually stored together, avoiding joins.
  • It scales out with sharding and stays available with replica sets.
  • Flexible schemas still need validation and careful design.

Example

Saving and finding a document (Node.js)javascript
import { MongoClient } from "mongodb";

const client = new MongoClient("mongodb://localhost:27017");
const users = client.db("shop").collection("users");

// A document can nest objects and arrays
await users.insertOne({
  name: "Ada",
  email: "ada@example.com",
  addresses: [{ city: "Istanbul", zip: "34000" }],
});

const ada = await users.findOne({ email: "ada@example.com" });

Readers ask

Is MongoDB a relational database?

No. MongoDB is a NoSQL document database: it stores documents in collections instead of rows in tables and does not require a fixed schema.

Does MongoDB support transactions?

Yes. Single-document writes have always been atomic, and since version 4.0 MongoDB also supports multi-document ACID transactions.

Is MongoDB free?

The Community Server is free to use under the Server Side Public License (SSPL). The company also sells an enterprise edition and the managed Atlas service, which has a free tier.

Often compared

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings