What is MongoDB?
MongoDB is a document database that stores records as flexible JSON-like documents. It is popular with developers who want data shaped like the objects in their code.
How does MongoDB store data?
As documents in collections, encoded in BSON, a binary form of JSON with extra types such as dates and decimals. A document can nest objects and arrays, so an order with its line items and delivery address fits in one record. Collections do not require every document to share a structure, though optional schema validation can enforce one. Each document has a unique _id, and a single document may be up to 16 MB.
How are queries and indexes written?
With filter documents and an aggregation pipeline. Simple queries match fields; the pipeline chains stages such as $match, $group, $lookup and $sort for reports. Indexes work much like relational ones, including compound, multikey (for arrays), text and geospatial indexes. Without a suitable index, a query scans the whole collection, so check plans with explain:
db.orders.createIndex({ customerId: 1, placedAt: -1 })
db.orders.find({ customerId: 7731, placedAt: { $gte: ISODate("2026-09-01") } })
.sort({ placedAt: -1 }).explain("executionStats").executionStats.totalDocsExamined
A well-indexed query examines about as many documents as it returns.
What is a replica set?
A group of MongoDB servers holding the same data, with one primary accepting writes and secondaries copying its operation log. If the primary fails, the members elect a new one within seconds, and drivers reconnect automatically. Three members are the minimum for automatic failover; two data members plus a small arbiter work but give less protection. Write concern majority makes the database confirm a write only when most members hold it, which survives a failover without losing acknowledged data.
When is sharding needed?
When one replica set can no longer hold the data or absorb the writes. Sharding splits a collection across several replica sets by a shard key, with config servers tracking where each range lives and mongos routers directing queries. It adds real complexity, and the shard key choice is hard to change, so scale up first: a single replica set on machines with plenty of memory and NVMe handles terabytes. A poor shard key, such as a timestamp, sends all new writes to one shard.
How should memory be configured?
Let the WiredTiger cache take about half of memory and leave the rest to the file system cache. By default WiredTiger uses 50 percent of RAM minus 1 GB, which suits a dedicated database server. Aim for the working set, the indexes plus frequently read documents, to fit in that cache. On BUSINESS-2 2024 with 64 GB DDR5 that gives roughly 31 GB of cache. Use XFS for data files, disable transparent huge pages if your version's documentation recommends it, and keep swap minimal.
| Setting | Where | Typical value |
|---|---|---|
| WiredTiger cache | storage.wiredTiger.engineConfig.cacheSizeGB | About half of RAM, default is fine |
| Bind address | net.bindIp | 127.0.0.1 plus the WireGuard address |
| Authentication | security.authorization | enabled |
| Replica set name | replication.replSetName | For example rs-orders |
How is MongoDB licensed?
The Community Server is free to use under the Server Side Public License, which is source-available but not approved as open source by the usual bodies. Using it to run your own applications is unrestricted; offering MongoDB itself as a service to others carries obligations. Fully open-source document databases with a compatible wire protocol, such as FerretDB on top of PostgreSQL, exist if licence terms matter to you. We do not sell database licences or managed MongoDB; you install and run it yourself.
How do I secure and back it up?
Enable authentication, bind to loopback and a private tunnel, and take consistent backups. Never expose port 27017 to the internet; exposed, unauthenticated MongoDB servers are among the most common data leaks. Replica set traffic between our servers should run over WireGuard, as a private network is not sold. For backups, mongodump works for small databases; for larger ones, snapshot a secondary's file system or use filesystem-level tools, and store copies on another server. Our Data backup article covers scheduling.
What hardware suits MongoDB?
Memory for the working set, NVMe for the journal and data, and three similar machines for a replica set. Three ESSENTIAL-S servers, each with 64 GB DDR5 and NVMe, make a solid small replica set at $46.20 each a month. Larger data sets suit BUSINESS-3 2026 or ENTERPRISE-a2 2026. Our NoSQL article places MongoDB among the other NoSQL families.
Machines for MongoDB replica sets
| Model | Processor | Cores | Memory | Drives | Port | Per month |
|---|---|---|---|---|---|---|
| ESSENTIAL-S | AMD Ryzen 7 9700X | 8 | 64 GB | 2x 512 GB SSD NVMe | 1 Gbps unmetered | $46.20 |
| ESSENTIAL-L | AMD Ryzen 9 9950X | 16 | 128 GB | 2x 960 GB SSD NVMe | 1 Gbps unmetered | $106.20 |
| BUSINESS-2 2024 | AMD EPYC 4344P | 8 | 64 GB | 2x 960 GB SSD NVMe | 3 Gbps unmetered | $109.80 |
| BUSINESS-3 2026 | AMD EPYC 4465P | 12 | 64 GB | 2x 960 GB SSD NVMe | 3 Gbps unmetered | $184.20 |
| ENTERPRISE-a2 2026 | AMD EPYC TURIN 9255 | 24 | 128 GB | 2x 1.92 TB SSD NVMe | 5 Gbps unmetered | $446.40 |
Related pages
NoSQL
Where the NoSQL movement came from, the CAP and BASE ideas behind it, how its families operate in production, and the mistakes teams commonly make.
Read moreNon-relational database
Databases that store data as documents, keys, columns or graphs instead of fixed tables: how each model works and when it beats SQL.
Read moreDatabase servers
NVMe machines with large memory for PostgreSQL, MySQL, MariaDB and MongoDB, from a single primary to replicated pairs.
Read moreData backup
Making copies that survive what destroys the original: full and incremental backups, the 3-2-1 rule, immutability, encryption, retention and restore testing.
Read moreQuestions and answers
Is MongoDB free?
The Community Server is free to use under the Server Side Public License. Running it for your own applications has no fee.
How many servers does a MongoDB replica set need?
Three for automatic failover with full data on each. Two data members plus an arbiter is possible but less resilient.
How much memory does MongoDB use?
By default the WiredTiger cache takes about half of RAM minus 1 GB, and the operating system file cache uses much of the rest.
Should MongoDB be reachable from the internet?
No. Bind it to localhost and a private tunnel such as WireGuard, enable authentication and firewall port 27017.
Do you offer managed MongoDB?
No. You install and manage MongoDB on your own dedicated servers with full root access.