SH-FOSS
SH-FOSS

SH-FOSS

c/sh-foss

FerretDB, an open-source alternative to MongoDB

FerretDB, an open-source alternative to MongoDB

FerretDB is an open-source alternative to MongoDB. It is a proxy that converts MongoDB 5.0+ wire protocol queries to SQL and uses PostgreSQL with DocumentDB extension as a database engine.

Screenshot 2025-02-24 at 11.25.14.png 18.32 KB
Based on the quick mention above, FerretDB uses PostgreSQL DocumentDB, a PostgreSQL extension developed and maintained by Microsoft to offer a native implementation of document-oriented NoSQL database, enabling seamless CRUD operations on BSON data types within a PostgreSQL framework. Powering vCore-based Azure Cosmos DB for MongoDB.

Do we really need FerretDB?

The developer of FerretDB states in its documentation page:

When MongoDB was initially created, it represented a welcome change from traditional relational databases with its ease of use and well-documented drivers that made it a popular choice among developers. However, as MongoDB moved away from its open-source roots to SSPL license, it introduced licensing complexities that made it unsuitable for many open-source and early-stage commercial projects.

FerretDB was created as an alternative to MongoDB – one that is easy to use (with familiar language and commands) and free from licensing restrictions. This makes it suitable for developers and organizations that need an open-source document database with MongoDB compatibility.

What about FerretDB performance vs MongoDB? 

At the moment when this post is written, there is no performance benchmark between FerretDB and MongoDB. But let's take a look what other people says about FerretDB when it is compared with MongoDB. 

Someone at Reddit's post says: 

JSONB columns in Postgres and gin indexes had generally better document storage performance than MongoDB, and in some benchmarks the difference widened to be pretty big. Just because MongoDB can only do one type of storage doesn't mean it performs better than Postgres for that usage. Mongo had some horizontal scaling advantages which it might still retain, but you can scale pretty far vertically with Postgres and extend it further with read replicas.

Since performance is good, a lot of enterprise customers use Postgres already. This means hosting an odd MongoDB application might be easier to maintain for enterprise teams if it is actually placed into the same Postgres cluster. I know I would not select a minor internal tool using a different database than the rest of our infrastructure, but this tool probably means we could integrate and manage an app using Mongo for storage just fine.

I'm not sure the title is bad. Lots of people have left Mongo because of the drastic change to an SSPL license. The use of the wire protocol and query language from Mongo means you don't need to worry about the license when picking it as a technology. That seems like the largest point to me.

Another one seems really positive about choosing PostgreSQL rather than MongoDB:

Postgres eats MongoDB for breakfast.

I am a happy PostgreSQL user since 1998. During my career, I saw terrible stuff: MySQL stuck transactions, 100MB images in Oracle BLOBs and swapping Windows Servers with MS SQL. But the worst of all was, without a doubt, customers trying to maintain or upgrade MongoDB clusters.

Personally, I'm still taking a grasp of understanding why should FerretDB exists other than this tool makes it easier for developer or early-stage commercial projects to keep their data while switching from MongoDB to FerretDB (PostgreSQL), just to avoid license complexities. 

How to install FerretDB?

Install FerretDB in your server is quite simple, all you need is a Docker and docker-compose.yml file. In your user home directory, create a directory for example

$ cd ~
$ mkdir ferretdb
$ cd ferretdb

Create a docker-compose.yml file with the following configuration

services:
  postgres:
    image: ghcr.io/ferretdb/postgres-documentdb:16
    platform: linux/amd64
    restart: on-failure
    environment:
      - POSTGRES_USER=username
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=postgres
    volumes:
      - ./data:/var/lib/postgresql/data

  ferretdb:
    image: ghcr.io/ferretdb/ferretdb:2
    restart: on-failure
    ports:
      - 27017:27017
    environment:
      - FERRETDB_POSTGRESQL_URL=postgres://username:password@postgres:5432/postgres

networks:
  default:
    name: ferretdb

Postgres container runs a pre-packaged PostgreSQL with DocumentDB extension and stores data in the ./data directory on the host. ferretdb runs FerretDB.

Now, let start the services with 

$ docker compose up -d

Nonetheless, open-source projects are always fascinating. If you need more detailed documentation on how to use and install FerretDB, you can visit FerretDB official documentation page


User Discussion
0 Discussion

Latest Discussions

SH-FOSS

SH-FOSS (Self-hosted & Free Open Source Software) - is an independent and open community to help you learn more about self-hosting and open-source software.

1 Members
0 Posts
0 Discussions

Community Rules

There are no rules in this community yet.

Ida Bagus Gede Pramana Adi Putra

Remote Software Developer for Zebralution GmbH (Lismio), Co-Founder of Reditor.com, Kodekativ.co, and Kataloogi.com under Codekraf Inc."}