Integrates DuckDB with MongoDB, enabling direct SQL queries and writes over MongoDB collections without ETL
Maintainer(s):
stephaniewang526
Installing and Loading
INSTALL mongo FROM community;
LOAD mongo;
Example
-- Attach to MongoDB
ATTACH 'host=localhost port=27017' AS mongo_db (TYPE MONGO);
-- Query collections with SQL
SELECT * FROM mongo_db.mydb.mycollection LIMIT 10;
-- Load a CSV directly into MongoDB
INSERT INTO mongo_db.mydb.mycollection
SELECT * FROM read_csv('data.csv');
About mongo
The duckdb-mongo extension provides direct SQL access to MongoDB collections without requiring data export or ETL processes. It supports both standalone MongoDB instances and MongoDB Atlas clusters.
Reading data:
- Automatic schema inference from sampled documents, with nested document flattening
- User-provided schemas and Atlas SQL
__schemadocument support - Query pushdown to MongoDB for filters, projections, limits, TopN, and aggregations (COUNT, SUM, MIN, MAX, AVG)
- BSON type mapping including ObjectId, Decimal128, arrays, and nested documents
Writing data (new in v0.3.0):
INSERT INTO– insert rows from any DuckDB source (CSV, Parquet, other databases, subqueries)CREATE TABLE AS SELECT– create new MongoDB collections from query resultsCOPY TO (FORMAT mongo)– bulk-load data into MongoDB collectionsDROP TABLE– drop MongoDB collections
Connections and security:
- MongoDB Atlas support via connection strings or DuckDB Secrets
- TLS/SSL encryption, custom CA certificates
mongo_enable_direct_scansetting to restrictmongo_scanto attached catalogs only
For detailed setup and usage instructions, visit the extension repository.
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| mongo_clear_cache | table | Clears the schema cache for all attached MongoDB databases. Useful when MongoDB schema changes. | NULL | [SELECT * FROM mongo_clear_cache()] |
| mongo_scan | table | Scans a MongoDB collection and returns its contents as a table. Supports optional filter and sample_size parameters. | NULL | [SELECT * FROM mongo_scan('mongodb://localhost:27017', 'mydb', 'mycollection'), SELECT * FROM mongo_scan('mongodb://localhost:27017', 'mydb', 'mycollection', filter := '{"status": "active"}')] |
Overloaded Functions
This extension does not add any function overloads.
Added Types
This extension does not add any types.
Added Settings
| name | description | input_type | scope | aliases |
|---|---|---|---|---|
| mongo_enable_direct_scan | Allow mongo_scan to use a connection string that is not from an attached MongoDB database. When false, mongo_scan is only allowed if the connection string exactly matches an attached Mongo catalog. | BOOLEAN | GLOBAL | [] |