feat(mongodb): [WRA-22] add MongoDB foreign data wrapper#606
Merged
Conversation
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>
…e underlying error
Contributor
There was a problem hiding this comment.
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_fdwimplementation 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.
- 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
imor
approved these changes
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_fdwas a native FDW.mongodb://andmongodb+srv://(incl. Atlas), TLS, replica sets, Vault for conn_string_id._docjsonb meta-column receives the full document for nested access.=, !=, <, <=, >, >=, IN, NOT IN, IS NULL, IS NOT NULL, AND, OR, ORDER BY, LIMIT.rowid_column(typically_id); UPDATE with NULL →$unset. ObjectId round-trips as 24-char hex.Out of scope for v1: aggregate pushdown, import_foreign_schema, LIKE → $regex, nested field paths, transactions, change streams.
Additional context
N/A