Skip to content

feat(mongodb): [WRA-22] add MongoDB foreign data wrapper#606

Merged
burmecia merged 23 commits into
mainfrom
bo/feat/mongodb-fdw
Jun 4, 2026
Merged

feat(mongodb): [WRA-22] add MongoDB foreign data wrapper#606
burmecia merged 23 commits into
mainfrom
bo/feat/mongodb-fdw

Conversation

@burmecia
Copy link
Copy Markdown
Member

@burmecia burmecia commented Jun 3, 2026

What kind of change does this PR introduce?

This PR is to add new native foreign data wrapper for MongoDB.

What is the current behavior?

No MongoDB FDW exists in the repo.

What is the new behavior?

Adds mongodb_fdw as a native FDW.

  • Built on the official mongodb Rust driver; supports mongodb:// and mongodb+srv:// (incl. Atlas), TLS, replica sets, Vault for conn_string_id.
  • Top-level BSON fields map by name to declared columns; missing fields → NULL. Optional _doc jsonb meta-column receives the full document for nested access.
  • Pushdown: =, !=, <, <=, >, >=, IN, NOT IN, IS NULL, IS NOT NULL, AND, OR, ORDER BY, LIMIT.
  • Writes via rowid_column (typically _id); UPDATE with NULL → $unset. ObjectId round-trips as 24-char hex.
  • Full BSON↔Postgres type mapping (bool, ints, doubles, Decimal128, text, ObjectId, DateTime, Document/Array →jsonb, Binary → bytea).

Out of scope for v1: aggregate pushdown, import_foreign_schema, LIKE → $regex, nested field paths, transactions, change streams.

Additional context

N/A

burmecia and others added 21 commits June 2, 2026 11:16
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add write-path support: begin_modify captures the target database/collection
and rowid_column from table options; insert builds a BSON Document from the
Row (skipping _doc and null fields) and calls insert_one; end_modify clears
the modify target. Includes a pg_test that seeds a collection, inserts a new
document via SQL INSERT, and verifies it is readable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add mongodb_types_read and mongodb_types_write pg_tests covering all
bson_to_cell and cell_to_bson conversion paths: int2/4/8, float4/8,
numeric (Decimal128/Double/Int64), text, ObjectId, timestamp,
timestamptz, jsonb (Document and Array), and bytea on read; bool, i2,
i4, i8, f4, f8, numeric, text, timestamp, timestamptz, and jsonb on
the write round-trip.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 3, 2026 02:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new native MongoDB foreign data wrapper (FDW) to the Wrappers extension, including core read/write support, CI wiring for a local MongoDB service, and end-user documentation for configuration, pushdown, and type mapping.

Changes:

  • Introduces mongodb_fdw implementation with scan + modify support and BSON↔Postgres type conversions.
  • Adds integration tests for scans, predicate pushdown, CRUD, and type round-trips against a local MongoDB instance.
  • Wires the new FDW into Cargo features, native FDW set, CI docker-compose, and documentation catalog.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
wrappers/src/fdw/mongodb_fdw/mongodb_fdw.rs Implements MongoDB FDW logic (query/pushdown, type mapping, CRUD, validator).
wrappers/src/fdw/mongodb_fdw/mod.rs Defines MongoDB FDW error type and error sanitization behavior.
wrappers/src/fdw/mongodb_fdw/tests.rs Adds pg_test-based integration tests for MongoDB FDW behavior.
wrappers/src/fdw/mongodb_fdw/README.md Adds a short wrapper README pointing to catalog docs.
wrappers/src/fdw/mod.rs Registers the MongoDB FDW module behind the mongodb_fdw feature.
wrappers/Cargo.toml Adds the mongodb_fdw feature and MongoDB/BSON dependencies.
wrappers/.ci/docker-compose-native.yaml Adds a MongoDB service for native FDW CI runs.
docs/catalog/mongodb.md Adds catalog documentation for the MongoDB wrapper (usage, options, pushdown, types).
Cargo.lock Locks new transitive dependencies pulled in by MongoDB/BSON crates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wrappers/src/fdw/mongodb_fdw/mongodb_fdw.rs
Comment thread wrappers/src/fdw/mongodb_fdw/mongodb_fdw.rs
Comment thread wrappers/src/fdw/mongodb_fdw/mongodb_fdw.rs Outdated
Comment thread wrappers/src/fdw/mongodb_fdw/mongodb_fdw.rs Outdated
Comment thread wrappers/src/fdw/mongodb_fdw/mongodb_fdw.rs Outdated
Comment thread docs/catalog/mongodb.md Outdated
- bson_to_cell: use try_from for INT2/INT4 conversions so out-of-range
  BSON integers error instead of silently wrapping
- cell_to_bson: return Result and error on unsupported Cell variants
  instead of silently encoding Bson::Null (prevents write data loss)
- iter_scan: drop cursor borrow before iterating tgt_cols to remove
  the per-row clone of the column list
- validator: also check server options — exactly one of conn_string or
  conn_string_id must be set
- docs: clarify that arbitrary OR predicates are not pushed down; only
  IN / NOT IN array forms become $in / $nin
@burmecia burmecia requested a review from imor June 3, 2026 13:08
@burmecia burmecia merged commit bf3077d into main Jun 4, 2026
11 checks passed
@burmecia burmecia deleted the bo/feat/mongodb-fdw branch June 4, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants