This is the multi-page printable view of this section.
MongoDB
On Debian 13 amd64, r4 exercised single-node DocumentDB and its standalone DocumentDB gateway. Drivers connect to the gateway and DocumentDB stores BSON in PostgreSQL tables. The instance retains its native PG administration connection. Both logical restore paths returned 63 documents through the original collection name. r4 gateway and recovery scope
Earlier PG18 reference environment
This section also retains the earlier Pigsty example with PostgreSQL 18, DocumentDB 1.0 and FerretDB. The r4 candidate used single-node DocumentDB 1.2 and its separate gateway. The distributed module depends on Citus, which is outside the Mimus support scope. Check driver and authentication behavior, scheduled jobs and collection catalog recovery for the stack you deploy.
Source and credit
DocumentDB is developed at documentdb/documentdb (originally opened at microsoft/documentdb); FerretDB at FerretDB/FerretDB. Deployment and extension notes in this section are adapted from the Pigsty documentation (© PGSTY, CC BY 4.0 / Apache-2.0). MongoDB is a trademark of MongoDB, Inc.; Mimus is not affiliated with MongoDB, Inc. See Licence and attribution.
1 - 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.
2 - Try it with Pigsty
This example uses the Pigsty mongo template and FerretDB from the earlier PG18 study. The configuration was conf/mongo.yml in Pigsty v4.5.0 and conf/fork/mongo.yml in its development sources at the time. Single-node Mimus 19.0.1 results
Single-node deployment
The default mongo template deploys PostgreSQL 18, the documentdb extension stack and a local FerretDB container on a single node (10.10.10.10):
Configure and deploy the PostgreSQL cluster, then install Docker and launch the
ferretdbapplication container on thepg-metanode:Connect from
mongoshor any MongoDB driver to the local loopback listener on port27017using the backend PostgreSQL user created by the template:
What the template configures
On the PostgreSQL side (pg_version: 18), the mongo template declares a mongod backend superuser, sets cron.database_name to postgres, preloads the DocumentDB and pg_cron libraries, and installs the required extensions in the postgres database:
On the gateway side, Pigsty deploys FerretDB (ghcr.io/ferretdb/ferretdb:2.7.0) as a stateless Docker application under apps.ferretdb.conf. The container connects to Pigsty’s local primary-routing service on port 5436 via host.docker.internal:
Three-node high-availability topology
Because FerretDB holds no state, high availability uses the standard PostgreSQL Patroni + etcd cluster layout (pg-mongo in the template):
- Each of the three PostgreSQL nodes (
10.10.10.11–10.10.10.13) runs a local FerretDB container bound to{{ inventory_hostname }}:27018and connected to its local port5436primary-routing service. - HAProxy runs TCP health checks (
option tcp-checkon port27018) across the three gateway containers and exposes a single floating endpoint at10.10.10.4:27017(mongo.pigsty). - Patroni and etcd handle PostgreSQL primary failover, while pgBackRest writes backups to a shared Silo or external S3 repository so backup history survives primary switchovers.
After uncommenting the pg-mongo cluster and the two additional etcd members in the template, deploy with:
Backup scope for DocumentDB 1.2
On PostgreSQL 19 with DocumentDB 1.2 and pg_cron 1.6.8, exclude the cron schema at dump time only if the destination may recreate the default jobs and you can discard user jobs, schedule or active-state changes, original job IDs, and execution history.
This omits the entire cron schema, including jobs registered by other extensions. To keep your options open, omit -N cron at dump time and retain the full custom-format archive. Use pg_restore --exit-on-error -N cron -d doclab doclab.dump only on a fresh destination that may start with default jobs. Other restores can still use the original scheduling data. If scheduling state must survive, keep it in the backup and use a tested restore procedure. Excluding only cron.job leaves history pointing to old job IDs.
A PostgreSQL logical archive of stock DocumentDB 1.2 can contain the physical document tables but omit the catalog that maps collection names to those tables. A successful pg_restore can therefore leave a collection returning zero documents. To preserve the full document database, use a tested same-version physical backup. On a separate restored instance, read known documents by collection name and check their indexes. Include documentdb_data whenever the backup is intended to preserve documents.
Operational notes
- Loopback binding by default: in single-node mode,
FERRETDB_BIND_ADDRdefaults to127.0.0.1. ChangeFERRETDB_BIND_ADDRonly when remote MongoDB clients need direct network access. - PostgreSQL is the security boundary:
FERRETDB_AUTH: trueauthenticates clients against PostgreSQL roles, but FerretDB does not implement MongoDB role-based authorization. Tightenpg_hba.confand change default passwords before production use. - Client TLS: the template does not enable client-side MongoDB TLS by default; configure certificates and the
FERRETDB_LISTEN_TLS*variables before exposing port27017on an untrusted network. - Upgrade smoke tests: FerretDB releases specify a preferred DocumentDB version while package repositories may ship a newer compatible
documentdbbuild. Run an authenticated CRUD smoke test after upgrading either component.
3 - Compatibility
This page describes the earlier PG18 stack. DocumentDB and its wire-protocol gateway implement different parts of MongoDB compatibility. The FerretDB and DocumentDB versions below belong to that upstream environment. The 19.0.1-r4 checks used the standalone DocumentDB gateway. Current verification scope
For the authoritative, version-specific command and operator matrices, consult the upstream documentation:
- DocumentDB (
v1.0-0): github.com/documentdb/documentdb - FerretDB (
v2.7.0): docs.ferretdb.io
What each layer covers
| Layer | Component | Compatibility responsibility |
|---|---|---|
| Wire protocol and session handling | FerretDB (2.7.0) or DocumentDB gateway | MongoDB wire framing (OP_MSG), driver handshakes (hello / isMaster), connection pooling, wire-level authentication and translation of client commands into SQL calls |
| BSON storage, operators and indexing | documentdb (1.0-0), documentdb_core, documentdb_extended_rum | BSON binary type (documentdb_core.bson), comparison and numeric rules, collection CRUD, aggregation pipeline execution, RUM path indexing, geospatial (postgis), vector (pgvector) and full-text queries |
Capabilities in the packaged DocumentDB 1.0 stack
Based on the DocumentDB 1.0-0 PostgreSQL packages shipped by PGDG and Pigsty (for PostgreSQL 15–18):
- BSON type and path operations (
documentdb_core): stores documents asdocumentdb_core.bson(withbsonqueryandbsonsequence), provides path extraction (->,->>,bson_get_value,bson_get_value_text), bytea/JSON conversion (bson_from_bytea,bson_to_bytea,bson_json_to_bson,bson_to_json_string), and B-tree and hash operator classes (bson_btree_ops,bson_hash_ops). Comparison, numeric promotion and indexing semantics follow DocumentDB’s BSON implementation rather than PostgreSQLjsonb. - Collection CRUD and aggregation (
documentdb): exposes collection management (documentdb_api.create_collection), document writes (documentdb_api.insert_oneand update/delete functions) and BSON query and aggregation execution (documentdb_api_catalog.bson_aggregation_find). - Indexing (
documentdb_extended_rum): provides an extended RUM index access method tailored for BSON documents and nested paths (documentdb.rum_library_load_option = 'require_documentdb_extended_rum'), including background non-blocking unique index builds (documentdb.enableNonBlockingUniqueIndexBuild, enabled by default sincev0.114) and posting-tree/leaf vacuum pruning in1.0-0. - Geospatial and vector workloads: integrates with
postgisfor geospatial queries andvector(pgvector) for vector similarity search (CREATE EXTENSION documentdb CASCADEinstalls both dependencies).
Known limitations and operational boundaries
- Not identical to every MongoDB server version: DocumentDB
1.0-0and FerretDB do not implement every command, aggregation stage or edge case of every MongoDB release. Applications should test the specific operators, index options, transaction patterns, schema validation rules and driver versions they rely on. - Authentication without MongoDB RBAC:
- In Pigsty’s
mongotemplate, FerretDB enables authentication (FERRETDB_AUTH: true) and checks credentials against PostgreSQL roles, but does not implement MongoDB role-based authorization. MongoDB roles cannot be used to isolate privileges. - In DocumentDB
1.0-0, custom role CRUD and post-join nested$lookupremain disabled by default behind feature flags.
- In Pigsty’s
- Version matching across components:
documentdb,documentdb_coreanddocumentdb_extended_rummust come from the same release line, and release upgrade SQL must be applied when updating existing databases. Because FerretDB releases specify a preferred DocumentDB version, run an authenticated CRUD smoke test after upgrading either FerretDB ordocumentdb. - r4 selects one compatibility protocol per instance. The connections guide documents the single-node DocumentDB gateway and logical restore checks.