当前位置: 首页 > news >正文

IvorySQL 4.6:DocumentDB+FerretDB 实现 MongoDB 兼容部署指南

背景

MongoDB 诞生之初,便以出色的易用性详尽的驱动程序文档脱颖而出,堪称对传统关系型数据库的一次重要革新,也正因如此,它迅速成为开发者社区的热门之选。

然而,随着其许可模式从开源转向 SSPL 许可证,MongoDB 的授权机制变得日趋复杂——这一变化直接导致它不再适配大量开源项目,同时也让许多处于早期阶段的商业项目难以将其纳入技术选型。

在此背景下,越来越多用户开始寻求 MongoDB 的文档数据库替代方案,其中,FerretDB 与搭载 DocumentDB 插件的 PostgreSQL 组合,凭借兼容特性与灵活的许可优势,成为了极具竞争力的优质选择。

DocumentDB 作为一个微软开发的引擎,用来驱动基于 vCore 的 Azure Cosmos DB for MongoDB,它引入了 BSON 数据类型,并提供 API 以便在原生 PostgreSQL 中无缝操作。

有不少人已经注意到,刚刚发布的 IvorySQL 4.6 有一个新特性是提供了兼容 MongoDB 的解决方案:使用 FerretDB 和 DocumentDB 提供兼容 MongoDB 的解决方案。这一解决方案使得 IvorySQL 4.6 除了兼容 Oracle 之外也兼容了 MongoDB。

ivydocumentdb 是基于微软 DocumentDB 并适配了 IvorySQL 的项目。它提供了面向文档的 NoSQL 数据库的原生实现,使用户能够在 IvorySQL 框架下,对 BSON(Binary JSON,二进制 JSON)数据类型进行无缝的 CRUD(创建、读取、更新、删除)操作。

本文将介绍如何使用 ivydocumentdb,在本地搭建一个含 DocumentDB 插件的 IvorySQL 环境,以平替 MongoDB。

安装方法

安装环境:CentOS Stream 9

下载源码

sudo dnf install -y git
git clone https://github.com/IvorySQL/ivydocumentdb.git
cd ivydocumentdb && git checkout IVYDOCDB_REL_4_STABLE

创建临时文件夹并复制安装脚本

sudo dnf install -y wget curl cmake unzip
sudo mkdir -p /tmp/install_setup
sudo cp ./scripts/* /tmp/install_setup
sudo chmod 777 /tmp/install_setup/*

准备编译环境

sudo dnf install -y epel-release
sudo dnf install -y bison readline-devel zlib-devel openssl-devel
sudo dnf groupinstall -y 'Development Tools'
sudo dnf config-manager --set-enabled crb
sudo dnf install -y perl-IPC-Run
sudo dnf install -y  gnupg2        tzdata pkgconf-pkg-config cmake       glibc-langpack-en     gcc     gdb      bison     flex     readline-devel     zlib-devel     krb5-devel     libtool     libicu-devel     openssl-devel perl-Test-Harness perl-core libxml2-devel

安装 IvorySQL 并编译相关插件

export MAKE_PROGRAM=cmake && sudo INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup /tmp/install_setup/install_setup_libbson.shsudo INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup /tmp/install_setup/install_setup_postgres.sh -d "/var/local/ivorysql/ivory-4" -v 4sudo env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH" IVORYVERSION=4 INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup /tmp/install_setup/install_setup_rum_oss.shsudo env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH" IVORYVERSION=4 INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup /tmp/install_setup/install_setup_citus_core_oss.sh 12sudo env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH" IVORYVERSION=4 INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup /tmp/install_setup/install_citus_indent.shsudo env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH"  IVORYVERSION=4 INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup /tmp/install_setup/install_setup_system_rows.shsudo env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH"  IVORYVERSION=4 INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup /tmp/install_setup/install_setup_pg_cron.shsudo INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup /tmp/install_setup/install_setup_intel_decimal_math_lib.shsudo INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup /tmp/install_setup/install_setup_pcre2.shsudo env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH"  INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup IVORYVERSION=4 /tmp/install_setup/install_setup_pgvector.shsudo dnf install -y proj-devel libxml2-devel json-c-devel geos-develsudo env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH"  INSTALL_DEPENDENCIES_ROOT=/tmp/install_setup IVORYVERSION=4 /tmp/install_setup/install_setup_postgis.sh

编译并安装 ivydocumentdb

sudo env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH" make
sudo env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH" make install
env "PATH=/var/local/ivorysql/ivory-4/bin:$PATH" IVY_VERSION_USED=4 /tmp/install_setup/start_oss_server.sh -d ~/data

当看到如下图所示内容,DocumentDB 就安装成功了。

图片1.png

使用方法

连接数据库并测试

为检查 DocumentDB 插件是否正常工作,需要连接数据库进行增删改查操作。
psql -U $USER -d postgres -p 9712

图片2.png

创建文档并插入数据:

SELECT documentdb_api.create_collection('documentdb','patient');select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P001", "name": "Alice Smith", "age": 30, "phone_number": "555-0123", "registration_year": "2023","conditions": ["Diabetes", "Hypertension"]}');
select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P002", "name": "Bob Johnson", "age": 45, "phone_number": "555-0456", "registration_year": "2023", "conditions": ["Asthma"]}');
select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P003", "name": "Charlie Brown", "age": 29, "phone_number": "555-0789", "registration_year": "2024", "conditions": ["Allergy", "Anemia"]}');
select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P004", "name": "Diana Prince", "age": 40, "phone_number": "555-0987", "registration_year": "2024", "conditions": ["Migraine"]}');
select documentdb_api.insert_one('documentdb','patient', '{ "patient_id": "P005", "name": "Edward Norton", "age": 55, "phone_number": "555-1111", "registration_year": "2025", "conditions": ["Hypertension", "Heart Disease"]}');

图片3.png

查询刚刚插入的数据:

SELECT document FROM documentdb_api.collection('documentdb','patient');

图片4.png

至此,用户就可以在 IvorySQL 上使用 documentdb_api 进行增删改查了。

FerretDB

最后,我们需要使用 FerretDB 作为一个 Proxy,将 MongoDB 5.0+ wire 协议查询转换为 SQL,并使用带有 DocumentDB 扩展的 IvorySQL 作为数据库引擎,完成对 MongoDB 的平替。

wget https://github.com/FerretDB/FerretDB/releases/download/v2.5.0/ferretdb-amd64-linux && chmod 777 ferretdb-amd64-linux
ferretdb-amd64-linux --postgresql-url "postgres://<username>:<user_password>@localhost:9712/postgres"

FerretDB 具体介绍及使用方式,可以参考 FerretDB 官网。

此时,FerretDB 就完成了部署,MongoDB 客户端通过 FerretDB 的 27017 端口及 IvorySQL 数据库的用户名密码,连上含 DocumentDB 插件的 IvorySQL,就可以顺利完成增删改查等操作。

总结

通过本文的步骤,我们成功在 CentOS Stream 9 环境下搭建了含 DocumentDB 插件的 IvorySQL 环境,并结合 FerretDB 实现了对 MongoDB 的平替。该方案不仅解决了 MongoDB 因 SSPL 许可证带来的适配难题,还借助 IvorySQL 本身兼容 Oracle 的特性,为企业提供了更灵活、多元的数据库选择。

对于开源项目或早期商业项目而言,此方案无需担心复杂的许可机制,同时能通过熟悉的 SQL 操作与 MongoDB 客户端交互,降低了技术迁移成本。后续,开发者可基于该环境进一步探索数据备份策略、性能优化方案,或结合实际业务场景扩展更多功能,充分发挥 IvorySQL 与 FerretDB 组合的优势,为业务发展提供稳定可靠的数据库支撑。


文章转载自:

http://250rcENI.rnygs.cn
http://BYLPxnTZ.rnygs.cn
http://lFtmUcw5.rnygs.cn
http://rhwKNq1P.rnygs.cn
http://Yt3cR2ci.rnygs.cn
http://dqQFFIm4.rnygs.cn
http://nc3Rib7z.rnygs.cn
http://CRlc7ZAP.rnygs.cn
http://eCBmHG5C.rnygs.cn
http://TZ2ZFTBN.rnygs.cn
http://VnclLhd5.rnygs.cn
http://rNecqczL.rnygs.cn
http://eeg6Mpzv.rnygs.cn
http://8u28pe03.rnygs.cn
http://tMB4mtOC.rnygs.cn
http://7zeLd129.rnygs.cn
http://7DwWd4sP.rnygs.cn
http://pDaifxh1.rnygs.cn
http://UjwVgPDD.rnygs.cn
http://HmPCAzaJ.rnygs.cn
http://1nnZUJ9a.rnygs.cn
http://Bu19E56f.rnygs.cn
http://kdvoRkL8.rnygs.cn
http://VoZ30pH6.rnygs.cn
http://8DqoH5Hb.rnygs.cn
http://mMPiMfh5.rnygs.cn
http://looTdWfZ.rnygs.cn
http://ASFHJpLc.rnygs.cn
http://OHoOpxeP.rnygs.cn
http://vlJAZhF5.rnygs.cn
http://www.dtcms.com/a/385878.html

相关文章:

  • UART,IIC,SPI总线(通信协议)
  • 记录一次小程序请求报错:600001
  • 光谱相机的新兴领域应用
  • GO学习记录十——发包
  • OpenLayers数据源集成 -- 章节十六:XML图层详解:OpenStreetMap数据的动态加载与智能样式渲染方案
  • vector 模拟实现 4 大痛点解析:从 memcpy 到模板嵌套的实战方案
  • tuple/dict/list 这三个数据类型在取值时候的区别
  • 用Python实现自动化的Web测试(Selenium)
  • Spring Boot 2.5.0 集成 Elasticsearch 7.12.0 实现 CRUD 完整指南(Windows 环境)
  • 第九章:使用Jmeter+Ant+Jenkins实现接口自动化测试持续集成
  • 使用IP的好处
  • 育碧确定《AC影》3月20日发售并分享系列游戏首发数据
  • 容器热升级机制在云服务器零停机部署中的实施规范
  • 贪心算法应用:时间序列分段(PAA)问题详解
  • 微信小程序开发教程(十五)
  • 语音DDS系统架构与实现方案:车机与手机语音助手的差异分析
  • 手机群控平台的工作效率
  • DBAPI免费版对比apiSQL免费版
  • node.js在vscode中npm等出现的一个问题
  • node.js学习笔记:中间件
  • Debian更新安全补丁常用命令
  • LeetCode:6.三数之和
  • 号称用rust重写的sqlite数据库tursodb与sqlite及duckdb性能比较
  • cuda stream
  • 云计算在云手机中的作用
  • C++STL学习:unordered_set/unordered_map
  • RTOS 任务状态与调度机制详解
  • 基于 Java EE+MySQL+Dart 实现多平台应用的音乐共享社区
  • 解密Tomcat的I/O模型:非阻塞之上,为何要兼容阻塞?
  • 时序数据库IoTDB如何支撑万亿级设备连接?