Getting Started with OLake for MongoDB
OLake helps you replicate data from MongoDB into local or S3-based data lakes using Parquet or Iceberg table formats. This tutorial walks you through every step of the setup—from creating necessary configuration files to running your first data sync.
TLDR:
- Create a
config.json
with your MongoDB connection details. - Create a
writer.json
with your Writer (Apache Iceberg or AWS S3) connection details. - Run
discover
to generate acatalog.json
of available streams. - Run
sync
to replicate data to your specified destination.
Introduction & Requirements
To use OLake, ensure you have:
- Docker installed and running on your machine.
- MongoDB credentials (hosts, replica set name, username/password if applicable).
- Install MongoDB
- Docker Compose instructions to spin up MongoDB replica sets
- Need sample dataset to ingest in MongoDB? Refer -> Sample Datasets
- AWS S3 credentials (if you plan to write data to AWS S3).
- Apache Iceberg and Catalog configuration credentials (if you plan to write data to Iceberg tables).
Refer here for more details on Writer requirements.
You will also need:
- An empty directory to store OLake configuration files and outputs. This guide will refer to it as
olake_directory
.
For setting up the project locally on your system and debugging configs to be made, follow this guide - Setting up debugger in VS Code
Step 1: Prepare Your Directory
-
Create a new directory on your local machine. Let’s call it
olake_directory
:mkdir olake_directory
-
Inside this folder, create two files:
writer.json
: Specifies your output destination (local or S3).config.json
: Contains connection settings for MongoDB (or other databases in the future).
cd olake_directory
touch writer.json
touch config.json
Folder Structure:
olake_directory/
├─ writer.json
└─ config.json
1.1 Example writer.json
Refer to Writer config section for individual writers or refer them here..
1.2 Example config.json
(MongoDB)
Below is a sample config.json
for connecting to a MongoDB replica set. Customize each field to match your environment.
{
"hosts": [
"host1:27017",
"host2:27017",
"host3:27017"
],
"username": "test",
"password": "test",
"authdb": "admin",
"replica-set": "rs0",
"read-preference": "secondaryPreferred",
"srv": true,
"server-ram": 16,
"database": "database",
"max_threads": 50,
"default_mode": "cdc",
"backoff_retry_count": 2,
"partition_strategy":""
}
Description of above parameters
Refer to source configuration for more details on config.json
.
Step 2: Generate a Catalog File
OLake needs to discover which collections (streams) exist in your MongoDB. This step will create a catalog.json
listing available streams, schemas, and default sync modes.
- Open your terminal in the same directory (say
olake_directory
) containingconfig.json
andwriter.json
. - Run the
discover
command using Docker:
- OLake Docker
- Locally run OLake
- macOS / Linux
- CMD
- Powershell
docker run \
-v "$HOME/PATH_TO_OLAKE_DIRECTORY:/mnt/config" \
olakego/source-mongodb:latest \
discover \
--config /mnt/config/config.json
docker run ^
-v "%USERPROFILE%\PATH_TO_OLAKE_DIRECTORY:/mnt/config" ^
olakego/source-mongodb:latest ^
discover ^
--config /mnt/config/config.json
docker run `
-v "$env:USERPROFILE\PATH_TO_OLAKE_DIRECTORY:/mnt/config" `
olakego/source-mongodb:latest `
discover `
--config /mnt/config/config.json
- macOS / Linux
- CMD
- Powershell
OLAKE_BASE_PATH="$HOME/PATH_TO_OLAKE_DIRECTORY/olake/drivers/mongodb/config" && \
./build.sh driver-mongodb discover \
--config "$OLAKE_BASE_PATH/config.json"
set "OLAKE_BASE_PATH=%USERPROFILE%\PATH_TO_OLAKE_DIRECTORY\olake\drivers\mongodb\config" && ^
./build.sh driver-mongodb discover ^
--config "%OLAKE_BASE_PATH%\config.json"
$OLAKE_BASE_PATH = "$env:USERPROFILE\PATH_TO_OLAKE_DIRECTORY\olake\drivers\mongodb\config"; `
./build.sh driver-mongodb discover `
--config "$OLAKE_BASE_PATH\config.json"
PATH_TO_OLAKE_DIRECTORY
is the absolute path where you have created the directory [as discussed above].
-v "$HOME/PATH_TO_OLAKE_DIRECTORY:/mnt/config" \
maps to -v /Users/JOHN_DOE_USERNAME/Desktop/projects/olake-docker:/mnt/config \
in macOS and Linux systems. Follow the same pattern in other systems.
Flag/Parameter | Description |
---|---|
discover | The OLake sub-command that scans MongoDB schemas. |
--config /mnt/config/config.json | Tells OLake where to find your MongoDB connection details. |
2.1 Understanding the catalog.json
File
After running discover
, OLake generates catalog.json
in olake_directory
with entries like:
{
"selected_streams": {
"otter_db": [
{
"partition_regex": "{now(),2025,YY}-{now(),06,MM}-{now(),13,DD}/{string_change_language,,}",
"stream_name": "stream_0"
},
{
"partition_regex": "{,1999,YY}-{,09,MM}-{,31,DD}/{latest_revision,,}",
"stream_name": "stream_8"
}
]
},
"streams": [
{
"stream": {
"name": "stream_8",
"namespace": "otter_db",
"type_schema": { ... },
"supported_sync_modes": [
"full_refresh",
"cdc"
],
"source_defined_primary_key": [
"_id"
],
"available_cursor_fields": [],
"sync_mode": "cdc"
}
},
// ... other streams
]
}
selected_streams
: The streams / tables / collections OLake will replicate.streams
: Metadata for each discovered collection, including schemas and sync modes (e.g.,cdc
,full_refresh
).partition_regex
: Specify the regex pattern. For more details, refer to S3 docs
Exclude Streams: You can remove unneeded collections by editing selected_streams
directly. For instance, deleting "customers"
if you only want to sync orders
.
Before (including customers
):
"selected_streams": {
"otter_db": [
{
"stream_name": "order",
"partition_regex": ""
},
{
"stream_name": "customer",
"partition_regex": ""
}
]
},
After (to exclude customers
):
"selected_streams": {
"otter_db": [
{
"stream_name": "order",
"partition_regex": ""
},
]
},
Step 3: Run Your First Data Sync
Now that you have catalog.json
, it’s time to sync data from MongoDB to your specified destination (local or S3).
- OLake Docker
- Locally run OLake
- macOS / Linux
- CMD
- Powershell
docker run \
-v "$HOME/PATH_TO_OLAKE_DIRECTORY:/mnt/config" \
olakego/source-mongodb:latest \
sync \
--config /mnt/config/config.json \
--catalog /mnt/config/catalog.json \
--destination /mnt/config/writer.json
docker run ^
-v "%USERPROFILE%\PATH_TO_OLAKE_DIRECTORY:/mnt/config" ^
olakego/source-mongodb:latest ^
sync ^
--config /mnt/config/config.json ^
--catalog /mnt/config/catalog.json ^
--destination /mnt/config/writer.json
docker run `
-v "$env:USERPROFILE\PATH_TO_OLAKE_DIRECTORY:/mnt/config" `
olakego/source-mongodb:latest `
sync `
--config /mnt/config/config.json `
--catalog /mnt/config/catalog.json `
--destination /mnt/config/writer.json
- macOS / Linux
- CMD
- Powershell
OLAKE_BASE_PATH="$HOME/PATH_TO_OLAKE_DIRECTORY/olake/drivers/mongodb/config" && \
./build.sh driver-mongodb sync \
--config "$OLAKE_BASE_PATH/config.json" \
--catalog "$OLAKE_BASE_PATH/catalog.json" \
--destination "$OLAKE_BASE_PATH/writer.json"
set "OLAKE_BASE_PATH=%USERPROFILE%\PATH_TO_OLAKE_DIRECTORY\olake\drivers\mongodb\config" && ^
./build.sh driver-mongodb sync ^
--config "%OLAKE_BASE_PATH%\config.json" ^
--catalog "%OLAKE_BASE_PATH%\catalog.json" ^
--destination "%OLAKE_BASE_PATH%\writer.json"
$OLAKE_BASE_PATH = "$env:USERPROFILE\PATH_TO_OLAKE_DIRECTORY\olake\drivers\mongodb\config"; `
./build.sh driver-mongodb sync `
--config "$OLAKE_BASE_PATH\config.json" `
--catalog "$OLAKE_BASE_PATH\catalog.json" `
--destination "$OLAKE_BASE_PATH\writer.json"
Flag/Parameter | Description |
---|---|
sync | The OLake sub-command that runs a data replication (snapshot + CDC). |
--config /mnt/config/config.json | MongoDB connection settings. |
--catalog /mnt/config/catalog.json | The file detailing which streams OLake will replicate. |
--destination /mnt/config/writer.json | The output configuration file (local or S3). |
- This command performs both the initial snapshot and, if configured, continuous CDC (
"default_mode": "cdc"
). - If you only want a full one-time snapshot, set the stream’s
sync_mode
to"full_refresh"
incatalog.json
.
Example: If your sync_mode
is "cdc"
, OLake will:
- Do a one-time full snapshot of each selected collection.
- Automatically begin listening to MongoDB’s oplog for near real-time changes.
When the sync finishes, you should see new files either:
- Locally (in the volume-mapped directory).
- On S3 (inside the specified
s3_path
).
Step 3.1 Synced Data
If you are using VS Code, install a parquet reader extension to visualize the parquet file contents that will be made post sync process.
Step 3.2 Synced Data Normalized
If you have turned on "normalization": true
in your writer.json
file, expect the below Level 1 Flattening of JSON data.
Read more about JSON flattening here - Flatten Object Types and Query Arrays in Semi-Structured Nested JSON
Running the sync command with normalization turned on
Output Data Dump
Step 3.3 Change output directory
If you need to output the parquet dump to some other location, you can make changes in the writer.json
file by appending the /mnt/config/my_directory
{
"type": "PARQUET",
"writer": {
"normalization":true,
"local_path": "/mnt/config/my_directory"
}
}
Here, /mnt/config
represents the olake_directory
.
Step 4: Resume Sync with a State File
If a sync is interrupted or you need to resume from a previous checkpoint, OLake automatically saves progress in a state.json
file. Use the --state
parameter to continue from that point:
- OLake Docker
- Locally run OLake
- macOS / Linux
- CMD
- Powershell
docker run \
-v "$HOME/PATH_TO_OLAKE_DIRECTORY:/mnt/config" \
olakego/source-mongodb:latest \
sync \
--config /mnt/config/config.json \
--catalog /mnt/config/catalog.json \
--destination /mnt/config/writer.json \
--state /mnt/config/state.json
docker run ^
-v "%USERPROFILE%\PATH_TO_OLAKE_DIRECTORY:/mnt/config" ^
olakego/source-mongodb:latest ^
sync ^
--config /mnt/config/config.json ^
--catalog /mnt/config/catalog.json ^
--destination /mnt/config/writer.json ^
--state /mnt/config/state.json
docker run `
-v "$env:USERPROFILE\PATH_TO_OLAKE_DIRECTORY:/mnt/config" `
olakego/source-mongodb:latest `
sync `
--config /mnt/config/config.json `
--catalog /mnt/config/catalog.json `
--destination /mnt/config/writer.json `
--state /mnt/config/state.json
- macOS / Linux
- CMD
- Powershell
OLAKE_BASE_PATH="$HOME/PATH_TO_OLAKE_DIRECTORY/olake/drivers/mongodb/config" && \
./build.sh driver-mongodb sync \
--config "$OLAKE_BASE_PATH/config.json" \
--catalog "$OLAKE_BASE_PATH/catalog.json" \
--destination "$OLAKE_BASE_PATH/writer.json" \
--state "$OLAKE_BASE_PATH/state.json"
set "OLAKE_BASE_PATH=%USERPROFILE%\PATH_TO_OLAKE_DIRECTORY\olake\drivers\mongodb\config" && ^
./build.sh driver-mongodb sync ^
--config "%OLAKE_BASE_PATH%\config.json" ^
--catalog "%OLAKE_BASE_PATH%\catalog.json" ^
--destination "%OLAKE_BASE_PATH%\writer.json" ^
--state "%OLAKE_BASE_PATH%\state.json"
$OLAKE_BASE_PATH = "$env:USERPROFILE\PATH_TO_OLAKE_DIRECTORY\olake\drivers\mongodb\config"; `
./build.sh driver-mongodb sync `
--config "$OLAKE_BASE_PATH\config.json" `
--catalog "$OLAKE_BASE_PATH\catalog.json" `
--destination "$OLAKE_BASE_PATH\writer.json" `
--state "$OLAKE_BASE_PATH\state.json"
Flag/Parameter | Description |
---|---|
--state /mnt/config/state.json | Points OLake to an existing state file. |
state.json
typically includes aresume token
(for MongoDB) or an offset for other databases, ensuring OLake does not reprocess records it has already synced.
A typical state.json
file has the following structure:
{
"type": "STREAM",
"streams": [
{
"stream": "stream_8",
"namespace": "otter_db",
"sync_mode": "",
"state": {
"_data": "8267B34D61000000022B0429296E1404"
}
},
{
"stream": "stream_0",
"namespace": "otter_db",
"sync_mode": "",
"state": {
"_data": "8267B34D61000000022B0429296E1404"
}
}
]
}
In this example, "_data": "8267B34D6..."
is a MongoDB resume token that tells OLake where to pick up the CDC stream.
For more details on the state.json
configuration, refer the state docs
Debugging
Follow the debugging instructions in this guide - Setting up debugger in VS Code
Docker Commands & Flags
Click here for more info about Docker Commands & Flags
Next Steps & Wrap-Up
- Check Your Output: Verify your Parquet files (or Iceberg tables) were created either locally or in your S3 bucket.
- Explore Schema Evolution: If your MongoDB documents gain new fields, OLake can adapt automatically. Watch for updated schemas in subsequent runs.
- Try More Destinations: OLake can also write to Iceberg on S3 (and more in the future). Update your writer config as needed.
- Analytics & Querying: Connect your newly created Parquet/Iceberg data to engines like Trino, Spark, or Presto for powerful querying.
Congratulations! You’ve completed your first OLake data replication. If you encounter any issues or have feedback, please visit our GitHub repository to open an issue or contribute.