FerretDBMongoDB 的开源替代品

联合创作 · 2023-10-01 01:43

FerretDB(以前称为 MangoDB)的成立是为了成为 MongoDB 的开源替代品。FerretDB 是一个开源代理,将 MongoDB wire protocol 查询转换为 SQL —— 使用 PostgreSQL 作为数据库引擎。

为什么我们需要 FerretDB?

MongoDB 放弃了它的开源根源;将许可证更改为 SSPL - 使其无法用于许多开源和早期商业项目。大多数 MongoDB 用户不需要 MongoDB 提供的许多高级功能;然而,他们需要一个易于使用的开源数据库解决方案。认识到这一点,FerretDB 将填补这一空白。

范围

FerretDB 将与 MongoDB 驱动程序兼容,并将努力作为 MongoDB 的替代品。

示例

1. 先在docker-compose.yml文件保存以下内容:

version: "3"

services:
  postgres:
    image: postgres:14
    container_name: postgres
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=user
      - POSTGRES_DB=mangodb
      - POSTGRES_HOST_AUTH_METHOD=trust

  postgres_setup:
    image: postgres:14
    restart: on-failure
    entrypoint: ["sh", "-c", "psql -h postgres -U user -d mangodb -c 'CREATE SCHEMA IF NOT EXISTS test'"]

  mangodb:
    image: ghcr.io/mangodb-io/mangodb:latest
    container_name: mangodb
    ports:
      - 27017:27017
    command: ["--listen-addr=:27017", "--postgresql-url=postgres://user@postgres:5432/mangodb"]

2. 通过postgres 容器运行存储数据的 PostgreSQL 14 数据库

3. 使用postgres_setup容器创建一个 PostgreSQL schematest,其作用类似于同名的 MangoDB 数据库

4. 使用mangodb 运行 MangoDB

5. 使用docker-compose up -d启动服务

6. 如果已经安装mongosh,只需运行它即可连接到 MangoDB 数据库test。如果没有,在临时 MongoDB 容器内运行运行以下命令mongosh,并将其附加到同一个 Docker 网络:

docker run --rm -it --network=mangodb_default --entrypoint=mongosh mongo:5 mongodb://mangodb/
浏览 4
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报