What MongoDB Does
- Document model — flexible schema, nested objects, arrays
- CRUD API — insertOne, find, updateOne, deleteOne
- Aggregation pipeline — stages for filter/group/project/lookup
- Indexing — single, compound, text, geospatial, vector (Atlas)
- Replication — replica sets for HA
- Sharding — horizontal scale across shards
- Transactions — multi-document ACID (v4+)
- Change streams — subscribe to data changes
- GridFS — large file storage
- Time-series — optimized time-series collections
Architecture
Primary-secondary replica set for HA. Writes go to primary, replicated to secondaries via oplog. Sharded clusters split data by shard key across multiple replica sets. WiredTiger is the default storage engine since 3.2.
Self-Hosting
# Docker Compose replica set
version: "3"
services:
mongo:
image: mongo:7
command: --replSet rs0 --bind_ip_all
ports:
- "27017:27017"
volumes:
- mongo-data:/data/db
volumes:
mongo-data:Since v5, MongoDB Community Edition uses SSPL. Read the license before SaaS-wrapping.
Key Features
- Document model (JSON-like)
- Flexible schema
- Aggregation pipeline
- Full-text search (Atlas Search)
- Vector search (Atlas, v7+)
- Time-series collections
- Change streams
- Multi-document transactions
- Geospatial queries
- Horizontal scaling (sharding)
Comparison
| Database | Model | Transactions | Scale |
|---|---|---|---|
| MongoDB | Document | Multi-doc ACID (v4+) | Sharding |
| PostgreSQL + JSONB | Relational + JSON | ACID | Vertical + logical repl |
| Couchbase | Document | ACID | Sharding |
| DynamoDB | Key-value + doc | ACID | Managed |
| Firestore | Document | ACID | Managed |
| Cassandra | Wide column | Eventual | Multi-master |
常见问题 FAQ
Q: MongoDB vs PostgreSQL? A: Postgres + JSONB 可以做 80% MongoDB 能做的事(加 ACID 和成熟 SQL 生态)。MongoDB 的优势是水平扩展、灵活 schema、社区 ORM(Mongoose)。
Q: SSPL 是什么意思? A: Source Available 但限制 SaaS 商用(如果你把 MongoDB 做成托管服务,必须开源整个服务栈)。自己用、嵌入应用完全 OK。
Q: 向量搜索? A: MongoDB Atlas 从 v7 开始内置向量搜索(RAG、语义搜索),本地 Community 版通过 vector search index 也可用。
来源与致谢 Sources
- Docs: https://www.mongodb.com/docs
- GitHub: https://github.com/mongodb/mongo
- License: SSPL