FerretDB — Open Source MongoDB Alternative on PostgreSQL
A truly open-source MongoDB-compatible database that translates MongoDB wire protocol queries into SQL, running on PostgreSQL or SQLite as the storage backend.
What it is
FerretDB is a truly open-source MongoDB-compatible database. It accepts MongoDB wire protocol connections and translates those queries into SQL, executing them against PostgreSQL or SQLite as the storage backend.
FerretDB targets teams that depend on MongoDB drivers and tools but want to avoid the SSPL license or vendor lock-in. If you already run PostgreSQL, FerretDB lets you keep your MongoDB application code while storing data in a fully relational engine.
How it saves time or tokens
Migrating from MongoDB to PostgreSQL usually means rewriting every query, changing drivers, and rethinking schema design. FerretDB eliminates that rewrite by acting as a transparent proxy. Your application connects to FerretDB using a standard MongoDB connection string, and FerretDB handles the SQL translation internally.
For AI agents that generate database queries, FerretDB means they can produce familiar MongoDB syntax while the data sits in PostgreSQL, reducing the complexity of prompt engineering for database operations.
How to use
- Start FerretDB with Docker Compose:
# docker-compose.yml
services:
ferretdb:
image: ghcr.io/ferretdb/ferretdb
ports:
- '27017:27017'
environment:
FERRETDB_POSTGRESQL_URL: postgres://user:pass@postgres:5432/ferretdb
postgres:
image: postgres:16
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: ferretdb
- Connect using any MongoDB driver or shell:
mongosh 'mongodb://localhost:27017/'
- Use standard MongoDB operations:
db.products.insertOne({ name: 'Widget', price: 9.99 })
db.products.find({ price: { $lt: 20 } })
FerretDB translates these into PostgreSQL queries under the hood.
Example
// Standard MongoDB aggregation pipeline
db.orders.aggregate([
{ $match: { status: 'completed' } },
{ $group: { _id: '$region', total: { $sum: '$amount' } } },
{ $sort: { total: -1 } }
])
This runs as a SQL query against PostgreSQL, returning results in MongoDB document format.
Related on TokRepo
- AI Tools for Database — AI-powered database tools and query generators
- Featured Workflows — Discover more curated open-source tools on TokRepo
Common pitfalls
- Expecting full MongoDB feature parity. FerretDB covers core CRUD and aggregation but some advanced features like change streams or sharding are not yet supported. Check the compatibility matrix before migrating.
- Using FerretDB for new greenfield projects. If you do not have existing MongoDB code, using PostgreSQL directly with a proper ORM is simpler and avoids the translation overhead.
- Ignoring PostgreSQL tuning. FerretDB performance depends on PostgreSQL configuration. Default settings may not handle the document-style workload patterns well.
- Failing to review community discussions and changelogs before upgrading. Breaking changes in major versions can disrupt existing workflows. Pin versions in production and test upgrades in staging first.
Frequently Asked Questions
FerretDB aims for MongoDB wire protocol compatibility, so most applications using standard MongoDB drivers can connect without code changes. However, it does not yet support every MongoDB feature. Core CRUD operations, basic aggregation, and indexing work. Advanced features like change streams, sharding, and some aggregation operators are still in development.
FerretDB supports PostgreSQL as its primary production backend and SQLite for lightweight or embedded use cases. PostgreSQL is recommended for production workloads because of its maturity, ACID guarantees, and ecosystem of monitoring and backup tools.
For typical CRUD workloads, FerretDB performance on PostgreSQL is comparable. The query translation layer adds minimal overhead. For heavy aggregation or write-intensive workloads, performance depends on PostgreSQL tuning and indexing. FerretDB benefits from PostgreSQL's mature query optimizer.
Yes. You can use mongodump to export data from MongoDB and mongorestore to import it into FerretDB. Since FerretDB speaks the MongoDB wire protocol, standard MongoDB tools work for data migration. The data is stored in PostgreSQL tables internally.
FerretDB is used in production by teams that need MongoDB compatibility on open-source infrastructure. It is backed by a commercial company and has regular releases. The PostgreSQL backend provides enterprise-grade reliability, backups, and replication.
Citations (3)
- FerretDB GitHub— FerretDB translates MongoDB wire protocol queries into SQL on PostgreSQL or SQLi…
- FerretDB Documentation— MongoDB wire protocol compatibility for open-source backends
- PostgreSQL Documentation— PostgreSQL as a document store backend
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.