title: 'MongoDB Data Connector'
sidebar_label: 'MongoDB Data Connector'
description: 'MongoDB Data Connector Documentation'
tags:
MongoDB is an open-source NoSQL database that stores data in flexible, JSON-like documents, allowing for dynamic schemas and easy scalability.
The MongoDB Data Connector enables federated/accelerated SQL queries on data stored in MongoDB databases.
Configuration
from
The from field takes the form mongodb:{table_name} where table_name is the table identifer in the MongoDB server to read from.
name
The dataset name. This will be used as the table name within Spice.
Example:
The dataset name cannot be a reserved keyword (opens in a new tab)
params
The MongoDB data connector can be configured by providing the following params. Use the secret replacement syntax (opens in a new tab) to load the secret from a secret store, e.g. ${secrets:my_mongodb_conn_string}.
| Parameter Name | Description |
|---|
mongodb_connection_string | The connection string to use to connect to the MongoDB server. This can be used instead of providing individual connection parameters. |
mongodb_user | The MongoDB username. |
mongodb_pass | The password to connect with. |
mongodb_host | The hostname of the MongoDB server. Defaults to localhost. |
mongodb_port | The port of the MongoDB server. Defaults to 27017. |
mongodb_db | The name of the database to connect to. Defaults to default. |
mongodb_sslmode | Optional. Specifies the SSL/TLS behavior for the connection, supported values: required: (default) This mode requires an SSL connection. If a secure connection cannot be established, server will not connect.preferred: Establishes an encrypted TLS/SSL connection but does not validate the server certificate or hostname (accepts invalid or self-signed certificates). If the server does not support TLS, the connection fails; it is never downgraded to plaintext.: This mode will not attempt to use an SSL connection, even if the server supports it. |
Types
The table below shows the MongoDB data types supported, along with the type mapping to Apache Arrow types in Spice.
| MongoDB Type | Arrow Type |
|---|
String | Utf8 |
Boolean | Boolean |
Int32 | Int32 |
Int64 | Int64 |
Double | Float64 |
Decimal128 | Decimal128 |
Binary | Binary |
Datetime without time | Date32 |
Datetime with time |
:::note
:::
Unnesting
Consider the following document:
Using mongodb_unnest_depth you can control the unnesting behavior. Here are the examples:
mongodb_unnest_depth: 0
mongodb_unnest_depth: 1
mongodb_unnest_depth: 2
Examples
Connecting using username and password and custom auth table
Connecting using SSL
Connecting using a Connection String
With custom connection pool settings
Secrets
Spice integrates with multiple secret stores to help manage sensitive data securely. For detailed information on supported secret stores, refer to the secret stores documentation (opens in a new tab). Additionally, learn how to use referenced secrets in component parameters by visiting the using referenced secrets guide (opens in a new tab).
Cookbook