Short answer: DynamoDB is AWS’s fully managed key-value and document database: you design tables around the queries you will run, pay per request or per provisioned capacity, and it runs only on AWS. MongoDB is a document database with ad hoc queries on any field, secondary indexes and an aggregation pipeline; you can run the free Community Server on any Linux server or rent it as MongoDB Atlas on AWS, Google Cloud or Azure.
# DynamoDB (AWS CLI): one customer's orders, newest first, strongly consistent
aws dynamodb query --table-name Orders \
--key-condition-expression "pk = :c" \
--expression-attribute-values '{":c": {"S": "CUSTOMER#42"}}' \
--consistent-read --no-scan-index-forward
# MongoDB (mongosh): the same, then a question nobody planned for
db.orders.find({ customerId: 42 }).sort({ createdAt: -1 })
db.orders.find({ status: "shipped", total: { $gt: 100 } })The second MongoDB line is the whole difference in miniature. In DynamoDB a query has to name a partition key, so a new question usually means a new index or a full table scan; in MongoDB any field can be filtered, and an index only makes it fast. Facts below are from AWS’s and MongoDB’s own documentation and pricing pages, read on 13 November 2026.
DynamoDB vs MongoDB at a glance
| Amazon DynamoDB | MongoDB | |
|---|---|---|
| What it is | Managed, serverless key-value and document service | Document database server; also sold managed as Atlas |
| Where it runs | AWS only | Any Linux, Windows or macOS server; Atlas on AWS, Google Cloud, Azure |
| Record size | Item up to 400 KB | BSON document up to 16 MiB, 100 levels of nesting |
| Queries | By partition key (plus sort key range); Scan reads everything | Any field, operators, aggregation pipeline |
| Indexes | Up to 20 global and 5 local secondary indexes per table | Single field, compound, multikey, wildcard, text, geospatial, hashed |
| Read consistency | Eventually consistent by default; strong reads on tables and LSIs | Reads from the primary by default; write concern majority by default |
| Transactions | Up to 100 items and 4 MB, one Region | Multi-document ACID on replica sets and sharded clusters |
| Pricing model | Per request (on-demand) or per provisioned capacity per hour, plus storage | Community: free, you pay for the server; Atlas: Free, Flex, Dedicated tiers |
| Licence | Proprietary service | Community Server under SSPL v1; Enterprise commercial |
| Self-hosting | No; DynamoDB local is for development and testing | Yes |
Data model: access patterns vs documents
A DynamoDB table has a partition key and, optionally, a sort key. Items with the same partition key are stored together and sorted by the sort key, so “all orders of customer 42 since June” is one cheap Query. Everything else follows from that: you list your access patterns first, then choose keys, often packing several entity types into one table with prefixed keys like CUSTOMER#42. Items are capped at 400 KB, attribute names included.
MongoDB stores JSON-like BSON documents of up to 16 MiB in collections, with no schema required. You model around the document your application reads (an order with its line items embedded, say) and add indexes for the fields you filter and sort on. Changing your mind later is cheaper: add an index, not a new table design.
Query model and limits
- DynamoDB:
GetItemby full key,Queryby partition key with an optional sort key condition,Scanover the whole table, plus PartiQL, a SQL-compatible language over the same operations. AQueryorScanreturns at most 1 MB per call, and a filter expression is applied after the read, so filtered-out items are still billed. A global secondary index keeps its own copy of the projected attributes under a different key, and its reads are always eventually consistent. - MongoDB:
find()with comparison, array and text operators, and the aggregation pipeline for grouping, joins between collections ($lookup) and reshaping. Without a matching index a query scans the collection, which is slow but works.
Consistency and transactions
A DynamoDB write that returns HTTP 200 is durably stored. Reads are eventually consistent by default and cost half as much; set ConsistentRead to true for a strongly consistent read on a table or local secondary index. Global secondary indexes and DynamoDB Streams are always eventually consistent. Transactions span up to 100 items and 4 MB, within one AWS account and Region.
MongoDB runs as a replica set: one primary takes writes and secondaries copy them. The implicit default write concern is majority, so a write is acknowledged once most voting members have it, unless arbiters reduce the count (then it is w: 1). Multi-document transactions work on replica sets and sharded clusters, with a default lifetime of 60 seconds.
Scaling and pricing model
DynamoDB: pay per request or per capacity
AWS offers two capacity modes. On-demand bills per read and write request: one read request unit covers a strongly consistent read of up to 4 KB (half a unit for eventually consistent, two for transactional), one write request unit covers a write of up to 1 KB. Provisioned bills the read and write capacity units you reserve per hour, whether you use them or not, and suits steady traffic; reserved capacity for one or three years lowers that. Storage is billed by the actual table size. The free tier gives 25 GB of storage and 25 read and 25 write capacity units per month per Region, on provisioned mode. Partitioning and scaling are automatic; there is no server to size.
MongoDB: your server, or Atlas
Community Server costs nothing to run; the bill is the machine under it. You scale up with RAM and disk, add secondaries for high availability, and shard across replica sets when one set is not enough, all managed by you. Atlas runs it for you: a free M0 cluster with 512 MB of storage, a Flex tier for development, and Dedicated clusters billed hourly with auto-scaling. The current release is MongoDB 9.0; the release notes list 9.0.8 on 10 November 2026.
Licences
DynamoDB is a closed AWS service. MongoDB Community Server and its tools are under the Server Side Public License v1 for every version released after 16 October 2018, including later patches of older series; earlier versions were under the AGPL v3. MongoDB’s licensing page says the aim is that enhancements are released to the community, and that organisations whose legal department does not accept the SSPL can buy commercial licences with MongoDB Enterprise Advanced.
Self-hosting on a VPS
Only MongoDB can be self-hosted. DynamoDB local, which AWS ships as a JAR (Java 17 or newer for v2.6.0 and later), a Maven dependency and the amazon/dynamodb-local Docker image, is meant for developing and testing without the web service: it listens on port 8000 and accepts any credentials. It is not a production database.
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
aws dynamodb list-tables --endpoint-url http://localhost:8000MongoDB on a VPS or dedicated server is an ordinary service. Install it from MongoDB’s own repository or run the official image with Docker, then:
mongodbinds to localhost by default; keepbindIpat127.0.0.1unless other servers must connect;security.authorizationisdisabledby default: enable it and create users before exposing anything;- if port 27017 must be reachable, allow only your application servers with UFW;
- give it RAM for the working set and fast disk, and back up with
mongodumpor disk snapshots to another machine.
DynamoDB or MongoDB: which one should you pick?
- Your stack already lives on AWS (Lambda, API Gateway): DynamoDB. No servers to run, IAM for access, and on-demand billing that follows your traffic.
- You know your access patterns and need predictable latency at any scale: DynamoDB, provided you are willing to model the table around them.
- Queries will change, or you need ad hoc filtering, reporting and aggregation: MongoDB.
- You want to avoid lock-in or run on your own servers: MongoDB Community, or Atlas on the cloud of your choice.
- Large documents (over 400 KB): MongoDB, or DynamoDB with the large part stored in S3 and a pointer in the item.
- Cost: on-demand DynamoDB grows with every request and costs little while traffic is low; a self-hosted MongoDB costs the same fixed server price busy or idle, plus your own time for patches and backups. Price both against your real request volume.
A cache in front of either is the usual next step; how Redis compares with a message log like Kafka is in Redis vs Kafka.
Frequently asked
Is DynamoDB the same as MongoDB?
No. Both store JSON-like records without a fixed schema, but DynamoDB is an AWS-only managed service queried mainly by partition and sort key, with items up to 400 KB. MongoDB is a database server you can run anywhere, with queries and indexes on any field and documents up to 16 MiB.
Can I self-host DynamoDB on my own server?
Not for production. AWS's DynamoDB local, available as a JAR, a Maven dependency and the amazon/dynamodb-local Docker image, is meant for development and testing without the web service. For a self-hosted document database, run MongoDB Community Server instead.
Is MongoDB free to use?
MongoDB Community Server is free to run under the Server Side Public License v1, which covers versions released after 16 October 2018. MongoDB Atlas has a free M0 tier with 512 MB of storage, and paid Flex and Dedicated tiers. Companies that cannot accept the SSPL can buy MongoDB Enterprise Advanced.
Which is cheaper, DynamoDB or MongoDB?
It depends on traffic. DynamoDB on-demand bills every read and write plus storage, so it is cheap at low volume and grows with use; provisioned capacity bills reserved throughput per hour. Self-hosted MongoDB costs a fixed server price plus the time to patch and back it up, which tends to favour steady, busy workloads.