Skip to content

This is the multi-page printable view of this section.

Return to the regular view of this page

MongoDB

Single-node DocumentDB 1.2 gateway verified in 19.0.1-r4, plus historical PG18 and FerretDB deployment notes.

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

How DocumentDB stores BSON in PostgreSQL and how a gateway translates the MongoDB wire protocol.

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:

LayerComponentResponsibility
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:

ExtensionShared library (shared_preload_libraries)SchemaRole
documentdb_corepg_documentdb_coredocumentdb_coreLow-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
documentdbpg_documentdbdocumentdb_apiPublic 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_rumpg_documentdb_extended_rumdocumentdb_extended_rum_catalogExtended RUM index access method for BSON documents and paths; selected by default via documentdb.rum_library_load_option = 'require_documentdb_extended_rum'
documentdb_distributedpg_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:

shared_preload_libraries = 'pg_cron, pg_documentdb_core, pg_documentdb, pg_documentdb_extended_rum'
cron.database_name = 'postgres'

Then install the extensions as a superuser in the target database:

CREATE EXTENSION documentdb CASCADE;
CREATE EXTENSION documentdb_extended_rum;

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:

SELECT documentdb_api.create_collection('appdb', 'people');

SELECT documentdb_api.insert_one(
  'appdb',
  'people',
  '{"_id": 1, "name": "Ada", "team": "storage"}',
  NULL
);

SELECT document
FROM documentdb_api_catalog.bson_aggregation_find(
  'appdb',
  '{"find": "people", "filter": {"team": "storage"}}'
);

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.

  1. Default gateway selection: Pigsty’s mongo template currently deploys FerretDB (ghcr.io/ferretdb/ferretdb:2.7.0) as a Docker application connected to documentdb, whereas upstream DocumentDB also maintains its own Rust gateway. Mimus must choose which gateway to ship and supervise alongside pgredis, pgetcd and pgsilo.
  2. Verification on the Mimus 1 kernel: pg_documentdb_core, pg_documentdb and pg_documentdb_extended_rum were 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 Pigsty documentdb packages are expected to load without recompilation, but this must be verified in CI.
  3. Authentication and role mapping: FerretDB authenticates users against PostgreSQL credentials (FERRETDB_AUTH: true), but does not implement MongoDB role-based authorization; in DocumentDB 1.0-0, custom role CRUD is also disabled by default. How MongoDB users map onto PostgreSQL roles and pg_hba.conf rules in the unified authentication model is undecided.
  4. Telemetry defaults: FerretDB’s Pigsty template sets FERRETDB_TELEMETRY: disabled, and upstream DocumentDB’s container image enables telemetry unless DOCUMENTDB_USAGE_TELEMETRY=false (or DO_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

Deploy PostgreSQL 18 with DocumentDB and a stateless FerretDB gateway using Pigsty’s mongo template.

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):

  1. Configure and deploy the PostgreSQL cluster, then install Docker and launch the ferretdb application container on the pg-meta node:

    ./configure -c mongo
    ./deploy.yml
    ./docker.yml -l pg-meta
    ./app.yml -l pg-meta
  2. Connect from mongosh or any MongoDB driver to the local loopback listener on port 27017 using the backend PostgreSQL user created by the template:

    mongosh 'mongodb://mongod:<password>@127.0.0.1:27017/'

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:

pg_version: 18
pg_users:
  - { name: mongod, password: <password>, superuser: true }
pg_databases:
  - { name: postgres, extensions: [ documentdb, postgis, vector, pg_cron, rum ] }
pg_parameters:
  cron.database_name: postgres
pg_extensions: [ documentdb, postgis, pgvector, pg_cron, rum ]
pg_libs: 'pg_documentdb, pg_documentdb_core, pg_documentdb_extended_rum, pg_cron, pg_stat_statements, auto_explain'

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:

docker_enabled: true
app: ferretdb
apps:
  ferretdb:
    conf:
      FERRETDB_IMAGE: ghcr.io/ferretdb/ferretdb:2.7.0
      FERRETDB_POSTGRESQL_URL: 'postgres://mongod:<password>@host.docker.internal:5436/postgres?pool_min_conns=1&pool_max_conns=20'
      FERRETDB_BIND_ADDR: 127.0.0.1
      FERRETDB_PORT: 27017
      FERRETDB_LISTEN_ADDR: ':27017'
      FERRETDB_AUTH: true
      FERRETDB_TELEMETRY: disabled

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):

  1. Each of the three PostgreSQL nodes (10.10.10.11–10.10.10.13) runs a local FerretDB container bound to {{ inventory_hostname }}:27018 and connected to its local port 5436 primary-routing service.
  2. HAProxy runs TCP health checks (option tcp-check on port 27018) across the three gateway containers and exposes a single floating endpoint at 10.10.10.4:27017 (mongo.pigsty).
  3. 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:

./configure -c fork/mongo
./deploy.yml
./docker.yml -l pg-mongo
./app.yml -l pg-mongo
mongosh 'mongodb://mongod:<password>@10.10.10.4:27017/'

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.

pg_dump -Fc -N cron -d doclab -f doclab.dump

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_ADDR defaults to 127.0.0.1. Change FERRETDB_BIND_ADDR only when remote MongoDB clients need direct network access.
  • PostgreSQL is the security boundary: FERRETDB_AUTH: true authenticates clients against PostgreSQL roles, but FerretDB does not implement MongoDB role-based authorization. Tighten pg_hba.conf and 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 port 27017 on an untrusted network.
  • Upgrade smoke tests: FerretDB releases specify a preferred DocumentDB version while package repositories may ship a newer compatible documentdb build. Run an authenticated CRUD smoke test after upgrading either component.

3 - Compatibility

How DocumentDB and the gateway divide MongoDB compatibility, what the packaged extensions support, and what remains untested in Mimus.

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:

What each layer covers

LayerComponentCompatibility responsibility
Wire protocol and session handlingFerretDB (2.7.0) or DocumentDB gatewayMongoDB 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 indexingdocumentdb (1.0-0), documentdb_core, documentdb_extended_rumBSON 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 as documentdb_core.bson (with bsonquery and bsonsequence), 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 PostgreSQL jsonb.
  • Collection CRUD and aggregation (documentdb): exposes collection management (documentdb_api.create_collection), document writes (documentdb_api.insert_one and 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 since v0.114) and posting-tree/leaf vacuum pruning in 1.0-0.
  • Geospatial and vector workloads: integrates with postgis for geospatial queries and vector (pgvector) for vector similarity search (CREATE EXTENSION documentdb CASCADE installs both dependencies).

Known limitations and operational boundaries

  • Not identical to every MongoDB server version: DocumentDB 1.0-0 and 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 mongo template, 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 $lookup remain disabled by default behind feature flags.
  • Version matching across components: documentdb, documentdb_core and documentdb_extended_rum must 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 or documentdb.
  • r4 selects one compatibility protocol per instance. The connections guide documents the single-node DocumentDB gateway and logical restore checks.