DocumentDB and the gateway
Unlike SQL Server or MySQL, MongoDB support on PostgreSQL is a service API protocol (see Architecture): it needs no kernel patch and no PostgreSQL fork. A stateless gateway listens on TCP port 27017, speaks the MongoDB wire protocol to drivers and mongosh, and translates each operation into SQL function calls against the DocumentDB extensions running inside stock PostgreSQL.
This architecture describes the Pigsty stack used in the earlier PG18 study. The Debian 13 amd64 r4 candidate exercised DocumentDB’s own gateway on a single node. r4 verification scope
Two-layer architecture
The stack separates protocol translation from storage and query execution:
| Layer | Component | Responsibility |
|---|---|---|
Wire-protocol gateway (port 27017) | FerretDB (FerretDB/FerretDB, Apache-2.0, Go) or DocumentDB gateway (documentdb/documentdb, MIT, Rust) | Accepts MongoDB wire-protocol connections (OP_MSG), multiplexes client sessions over a PostgreSQL connection pool, and translates commands into documentdb_api SQL calls |
Storage and execution engine (port 5432) | PostgreSQL 18 + DocumentDB extensions (documentdb/documentdb, MIT, C) | Stores BSON documents in PostgreSQL tables, indexes BSON paths with RUM/GIN/B-tree/HNSW/GiST, and executes CRUD, aggregation pipelines, geospatial, full-text and vector operators inside PostgreSQL |
Because the gateway holds no persistent state, PostgreSQL owns durability, ACID transactions, write-ahead logging, point-in-time recovery (pgBackRest), high availability (Patroni) and monitoring. In a multi-node cluster, each node can run a local stateless gateway instance behind HAProxy.
The DocumentDB extensions
DocumentDB (1.0 / v1.0-0, MIT License, packaged for PostgreSQL 15–18 by PGDG and Pigsty) consists of four PostgreSQL extensions:
| Extension | Shared library (shared_preload_libraries) | Schema | Role |
|---|---|---|---|
documentdb_core | pg_documentdb_core | documentdb_core | Low-level BSON data type (documentdb_core.bson, bsonquery, bsonsequence), path extraction (->, ->>, bson_get_value), serialization (bson_from_bytea, bson_json_to_bson) and B-tree / hash operator classes |
documentdb | pg_documentdb | documentdb_api | Public PostgreSQL API for collections, CRUD, aggregation, geospatial, full-text and vector queries. Depends on documentdb_core, pg_cron, postgis, tsm_system_rows and vector (pgvector) |
documentdb_extended_rum | pg_documentdb_extended_rum | documentdb_extended_rum_catalog | Extended RUM index access method for BSON documents and paths; selected by default via documentdb.rum_library_load_option = 'require_documentdb_extended_rum' |
documentdb_distributed | pg_documentdb_distributed | — | Internal multi-node execution layer integrating documentdb with Citus (citus required); retired from standard single-node packages |
Enabling the single-node DocumentDB stack in postgresql.conf requires preloading the three libraries alongside pg_cron and restarting PostgreSQL:
Then install the extensions as a superuser in the target database:
CREATE EXTENSION documentdb CASCADE automatically installs documentdb_core, pg_cron, postgis, tsm_system_rows and vector when their packages are present. Both extensions are superuser-only and non-relocatable.
SQL API under the hood
Installing documentdb without a gateway exposes its SQL surface inside PostgreSQL, but does not open a listener on port 27017. When a gateway is running, it translates MongoDB wire commands into calls to documentdb_api and documentdb_api_catalog functions. The same functions can be called directly from psql:
documentdb_core.bson follows MongoDB BSON comparison, numeric and indexing rules rather than PostgreSQL jsonb semantics. Indexes on document collections should be created and managed through the DocumentDB APIs or a MongoDB client connected to the gateway, rather than by building indexes directly on internal operator classes.
Questions from the PG18 study
The November 2026 PG18 study recorded the following four questions. Its gateway and binary-compatibility assumptions refer to that historical environment.
- Default gateway selection: Pigsty’s
mongotemplate currently deploys FerretDB (ghcr.io/ferretdb/ferretdb:2.7.0) as a Docker application connected todocumentdb, whereas upstream DocumentDB also maintains its own Rust gateway. Mimus must choose which gateway to ship and supervise alongsidepgredis,pgetcdandpgsilo. - Verification on the Mimus 1 kernel:
pg_documentdb_core,pg_documentdbandpg_documentdb_extended_rumwere not part of the 11-extension smoke matrix run on 2026-11-07 (see Extension matrix). Because Mimus 1 keeps Level A binary compatibility with stock PostgreSQL 18 (see ABI compatibility), stock PGDG and Pigstydocumentdbpackages are expected to load without recompilation, but this must be verified in CI. - Authentication and role mapping: FerretDB authenticates users against PostgreSQL credentials (
FERRETDB_AUTH: true), but does not implement MongoDB role-based authorization; in DocumentDB1.0-0, custom role CRUD is also disabled by default. How MongoDB users map onto PostgreSQL roles andpg_hba.confrules in the unified authentication model is undecided. - Telemetry defaults: FerretDB’s Pigsty template sets
FERRETDB_TELEMETRY: disabled, and upstream DocumentDB’s container image enables telemetry unlessDOCUMENTDB_USAGE_TELEMETRY=false(orDO_NOT_TRACK=1) is set (native RPM/DEB extension packages are unaffected). Mimus packaging must keep telemetry disabled by default.
