FORMAT 'bson.bson'
COPY … FROM · import COPY … TO · exportBSON COPY. Byte-preserving BSON file import and export
-- Load a file into an existing local table
COPY my_table FROM 'data.bson' (FORMAT 'bson.bson');
-- Write a query's rows out to a file
COPY (SELECT * FROM my_table) TO 'out.bson' (FORMAT 'bson.bson');
Options
Pass these inside the COPY statement's parentheses, after FORMAT. Unknown options are rejected.
- modeVARCHAR
- Document representation: 'raw' (default), exactly one BLOB column.
- max_document_sizeBIGINT
- Maximum bytes per BSON document, including its prefix; default 16 MiB. Applies to import and export.
Full reference
Import or export raw BSON documents using COPY with FORMAT 'bson.bson' (replace the first bson with your attached catalog name). Requires exactly one BLOB column, one complete BSON document per row. MODE defaults to 'raw'; typed rows are not supported. Local files only; reads stream in bounded batches. Invalid documents, duplicate keys, truncated files, NULL rows, and oversized documents fail the COPY. MAX_DOCUMENT_SIZE defaults to 16777216 bytes (16 MiB), and may be raised up to 2147483647. Bytes are preserved without decoding/re-encoding. Export preserves source order (use ORDER BY for deterministic ordering), stages batches in shared storage, and atomically replaces the destination only after successful writing. Empty export creates a zero-byte file.
Import and export
Create the destination table in a writable DuckDB schema, then import a local mongodump document file. Qualify the format by the catalog's ATTACH alias.
COPY <target_table> FROM '<input_path>' (FORMAT '<catalog>.bson');
COPY (<query_returning_one_blob_column>) TO '<output_path>'
(FORMAT '<catalog>.bson', MODE 'raw');
A bad import aborts the statement and reports its filename and document byte offset. A bad export reports its source row and leaves an existing destination intact. COPY accepts one uncompressed file; cloud paths, globs, collection metadata and mongodump archive containers are outside this format. Paths are resolved on the worker's filesystem. MAX_DOCUMENT_SIZE can be raised explicitly for larger documents.