documentdb

微软DocumentDB的API层

概览

扩展包名版本分类许可证语言
documentdb0.113SIMMITC
ID扩展名BinLibLoadCreateTrustReloc模式
9000documentdb-
9010documentdb_core-
9020documentdb_distributed-
9030documentdb_extended_rum-
相关扩展documentdb_core pg_cron postgis tsm_system_rows vector mongo_fdw wal2mongo pg_jsonschema jsquery
下游依赖documentdb_distributed documentdb_extended_rum

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY0.1131817161514documentdbdocumentdb_core, pg_cron, postgis, tsm_system_rows, vector
RPMPIGSTY0.1131817161514documentdb_$vpostgresql$v-contrib, pg_cron_$v, pgvector_$v, rum_$v, postgis36_$v
DEBPIGSTY0.1131817161514postgresql-$v-documentdbpostgresql-$v-cron, postgresql-$v-pgvector, postgresql-$v-rum, postgresql-$v-postgis-3
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PIGSTY MISS
el8.aarch64PIGSTY MISS
el9.x86_64PIGSTY MISS
el9.aarch64PIGSTY MISS
el10.x86_64PIGSTY MISS
el10.aarch64PIGSTY MISS
d12.x86_64PIGSTY MISS
d12.aarch64
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY MISS
d13.x86_64PIGSTY MISS
d13.aarch64PIGSTY MISS
u22.x86_64
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY MISS
u22.aarch64
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY MISS
u24.x86_64
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY MISS
u24.aarch64
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY 0.113
PIGSTY MISS
u26.x86_64PIGSTY MISS
u26.aarch64PIGSTY MISS

构建

您可以使用 pig build 命令构建 documentdb 扩展的 RPM / DEB 包:

pig build pkg documentdb         # 构建 RPM / DEB 包

安装

您可以直接安装 documentdb 扩展包的预置二进制包,首先确保 PGDGPIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install documentdb;          # 当前活跃 PG 版本安装
pig ext install -y documentdb -v 18  # PG 18
pig ext install -y documentdb -v 17  # PG 17
pig ext install -y documentdb -v 16  # PG 16
pig ext install -y documentdb -v 15  # PG 15
dnf install -y documentdb_18       # PG 18
dnf install -y documentdb_17       # PG 17
dnf install -y documentdb_16       # PG 16
dnf install -y documentdb_15       # PG 15
apt install -y postgresql-18-documentdb   # PG 18
apt install -y postgresql-17-documentdb   # PG 17
apt install -y postgresql-16-documentdb   # PG 16
apt install -y postgresql-15-documentdb   # PG 15

预加载配置

shared_preload_libraries = 'pg_documentdb, pg_documentdb_core, pg_cron';

创建扩展

CREATE EXTENSION documentdb CASCADE;  -- 依赖: documentdb_core, pg_cron, postgis, tsm_system_rows, vector

用法

来源:READMECHANGELOGdocumentdb.controldocumentdb_core.controldocumentdb_extended_rum.control

documentdb 是以 PostgreSQL 扩展实现的 MongoDB 兼容文档数据库。它在 PostgreSQL 中加入 BSON 存储和 API,并可通过可选 gateway 层服务 MongoDB wire-protocol 客户端。FerretDB 2.0+ 可以使用 DocumentDB 作为后端。

组件

公开扩展接口拆分为多个相关扩展:

  • documentdb_core:BSON 数据类型与底层 BSON 操作。
  • documentdb:面向文档 CRUD 与查询行为的公开 API。
  • documentdb_extended_rum:DocumentDB 索引使用的 extended RUM access method。
  • pg_documentdb_gw:本地 Docker 镜像和 MongoDB 兼容客户端使用的 gateway protocol layer。

在需要 API 的每个数据库中安装 SQL 扩展:

CREATE EXTENSION IF NOT EXISTS documentdb CASCADE;

0.113-0documentdb.control 声明依赖 documentdb_corepg_crontsm_system_rowsvectorpostgis。gateway container 监听 MongoDB 兼容端口;README 示例使用 10260,避免与本机 MongoDB 服务冲突。

MongoDB 客户端示例

import pymongo

client = pymongo.MongoClient(
    "mongodb://user:pass@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true"
)

db = client["quickStartDatabase"]
coll = db.create_collection("quickStartCollection")

coll.insert_one({"name": "Alice", "email": "alice@example.com"})
print(coll.find_one({"name": "Alice"}))

上游 README 也展示了通过普通 MongoDB driver 执行 aggregation pipeline:

pipeline = [
    {"$match": {"name": "Alice"}},
    {"$project": {"_id": 0, "name": 1, "email": 1}},
]

for doc in coll.aggregate(pipeline):
    print(doc)

版本说明

本项目 CSV 跟踪 DocumentDB 0.113,覆盖 PostgreSQL 15-18。上游 tag 为 v0.113-0;control files 报告 default_version = '0.113-0'

0.1110.113 的 changelog 主要是 query planner、collation 与 index correctness 方面的工作:

  • 0.113-0 为带 $in$nin 的非唯一 ordered indexes 增加 opt-in collation support,并在 feature flag 后支持清理 ordered TTL indexes 上的 dead index entries。
  • 0.112-0 移除较旧的 composite-returning bson_update_document UDF 路径,扩展非唯一 ordered-index collation support,并改进 $group 和 accumulator 执行。
  • 0.111-0 增加后台初始化 job infrastructure、更多 $group 校验、collation/index pushdown 改进,以及多个 crash fix。

注意事项

  • DocumentDB 是多扩展栈;CREATE EXTENSION documentdb CASCADE 是通常入口,但如果需要 MongoDB wire compatibility,实际部署还需要 gateway/runtime pieces。
  • changelog 中部分功能受 documentdb.* feature flags 控制。将行为写成 always-on 前,先核对确切安装版本中的 flag 默认值。
  • documentdb_extended_rum 可 relocation,但 documentdbdocumentdb_core 不可 relocation。

最后修改 2026-07-02: extension update 2026-07-02 (d4da20c)