2023-04-25 16:58:47 +02:00
---
2023-07-14 14:12:27 +02:00
title: Run the MongoDB Connector Externally
slug: /connectors/database/mongodb/yaml
2023-04-25 16:58:47 +02:00
---
2023-07-14 14:12:27 +02:00
# Run the MongoDB Connector Externally
2023-04-25 16:58:47 +02:00
{% multiTablesWrapper %}
| Feature | Status |
2023-08-20 20:08:30 -07:00
|:-------------------|:-----------------------------|
2023-04-25 16:58:47 +02:00
| Stage | PROD |
| Metadata | {% icon iconName="check" /%} |
| Query Usage | {% icon iconName="cross" /%} |
2023-04-27 12:01:26 +05:30
| Data Profiler | {% icon iconName="cross" /%} |
| Data Quality | {% icon iconName="cross" /%} |
2023-08-20 20:08:30 -07:00
| Lineage | {% icon iconName="cross" /%} |
2023-04-25 16:58:47 +02:00
| DBT | {% icon iconName="cross" /%} |
| Supported Versions | -- |
| Feature | Status |
2023-08-20 20:08:30 -07:00
|:-------------|:-----------------------------|
| Lineage | {% icon iconName="cross" /%} |
2023-04-25 16:58:47 +02:00
| Table-level | {% icon iconName="cross" /%} |
| Column-level | {% icon iconName="cross" /%} |
{% /multiTablesWrapper %}
2023-07-14 14:12:27 +02:00
In this section, we provide guides and references to use the MongoDB connector.
2023-04-25 16:58:47 +02:00
2023-07-14 14:12:27 +02:00
Configure and schedule MongoDB metadata workflows from the OpenMetadata UI:
2023-04-25 16:58:47 +02:00
- [Requirements ](#requirements )
- [Metadata Ingestion ](#metadata-ingestion )
2023-08-25 08:49:58 +02:00
{% partial file="/v1.1.2/connectors/ingestion-modes-tiles.md" variables={yamlPath: "/connectors/database/mongodb/yaml"} /%}
2023-07-14 14:12:27 +02:00
2023-08-25 08:49:58 +02:00
{% partial file="/v1.1.2/connectors/external-ingestion-deployment.md" /%}
2023-07-14 14:12:27 +02:00
2023-04-25 16:58:47 +02:00
## Requirements
{%inlineCallout icon="description" bold="OpenMetadata 0.12 or later" href="/deployment"%}
To deploy OpenMetadata, check the Deployment guides.
{%/inlineCallout%}
2023-07-14 14:12:27 +02:00
To fetch the metadata from MongoDB to OpenMetadata, the MongoDB user must have access to perform `find` operation on collection and `listCollection` operations on database available in MongoDB.
2023-04-25 16:58:47 +02:00
### Python Requirements
2023-07-14 14:12:27 +02:00
To run the MongoDB ingestion, you will need to install:
2023-04-25 16:58:47 +02:00
```bash
2023-07-14 14:12:27 +02:00
pip3 install "openmetadata-ingestion[mongo]"
2023-04-25 16:58:47 +02:00
```
## Metadata Ingestion
All connectors are defined as JSON Schemas.
2023-07-14 14:12:27 +02:00
[Here ](https://github.com/open-metadata/OpenMetadata/blob/main/openmetadata-spec/src/main/resources/json/schema/entity/services/connections/database/mongoDBConnection.json )
you can find the structure to create a connection to MongoDB.
2023-04-25 16:58:47 +02:00
In order to create and run a Metadata Ingestion workflow, we will follow
the steps to create a YAML configuration able to connect to the source,
process the Entities if needed, and reach the OpenMetadata server.
The workflow is modeled around the following
[JSON Schema ](https://github.com/open-metadata/OpenMetadata/blob/main/openmetadata-spec/src/main/resources/json/schema/metadataIngestion/workflow.json )
### 1. Define the YAML Config
2023-07-14 14:12:27 +02:00
This is a sample config for MongoDB:
2023-04-25 16:58:47 +02:00
{% codePreview %}
{% codeInfoContainer %}
#### Source Configuration - Service Connection
{% codeInfo srNumber=1 %}
2023-07-14 14:12:27 +02:00
**username**: Username to connect to Mongodb. This user must have access to perform `find` operation on collection and `listCollection` operations on database available in MongoDB.
2023-04-25 16:58:47 +02:00
{% /codeInfo %}
{% codeInfo srNumber=2 %}
2023-07-14 14:12:27 +02:00
**password**: Password to connect to MongoDB.
2023-04-25 16:58:47 +02:00
{% /codeInfo %}
{% codeInfo srNumber=3 %}
2023-07-14 14:12:27 +02:00
**hostPort**: The hostPort parameter specifies the host and port of the MongoDB. This should be specified as a string in the format `hostname:port` . E.g., `localhost:27017` .
2023-04-25 16:58:47 +02:00
{% /codeInfo %}
{% codeInfo srNumber=5 %}
2023-07-14 14:12:27 +02:00
**connectionURI**: MongoDB connection string is a concise string of parameters used to establish a connection between an OpenMetadata and a MongoDB database. For ex. `mongodb://username:password@mongodb0.example.com:27017` .
2023-04-25 16:58:47 +02:00
{% /codeInfo %}
{% codeInfo srNumber=6 %}
**databaseName**: Optional name to give to the database in OpenMetadata. If left blank, we will use default as the database name.
{% /codeInfo %}
#### Source Configuration - Source Config
{% codeInfo srNumber=9 %}
The `sourceConfig` is defined [here ](https://github.com/open-metadata/OpenMetadata/blob/main/openmetadata-spec/src/main/resources/json/schema/metadataIngestion/databaseServiceMetadataPipeline.json ):
**markDeletedTables**: To flag tables as soft-deleted if they are not present anymore in the source system.
**includeTables**: true or false, to ingest table data. Default is true.
**includeViews**: true or false, to ingest views definitions.
2023-08-20 20:08:30 -07:00
**databaseFilterPattern**, **schemaFilterPattern** , **tableFilterPattern** : Note that the filter supports regex as include or exclude. You can find examples [here ](/connectors/ingestion/workflows/metadata/filter-patterns/database )
2023-04-25 16:58:47 +02:00
{% /codeInfo %}
#### Sink Configuration
{% codeInfo srNumber=10 %}
To send the metadata to OpenMetadata, it needs to be specified as `type: metadata-rest` .
{% /codeInfo %}
2023-08-25 08:49:58 +02:00
{% partial file="/v1.1.2/connectors/workflow-config.md" /%}
2023-04-25 16:58:47 +02:00
#### Advanced Configuration
{% codeInfo srNumber=7 %}
**Connection Options (Optional)**: Enter the details for any additional connection options that can be sent to Athena during the connection. These details must be added as Key-Value pairs.
{% /codeInfo %}
{% /codeInfoContainer %}
{% codeBlock fileName="filename.yaml" %}
```yaml
source:
2023-07-14 14:12:27 +02:00
type: mongodb
serviceName: local_mongodb
2023-04-25 16:58:47 +02:00
serviceConnection:
config:
2023-07-14 14:12:27 +02:00
type: MongoDB
connectionDetails:
2023-04-25 16:58:47 +02:00
```
```yaml {% srNumber=1 %}
2023-07-14 14:12:27 +02:00
username: username
2023-04-25 16:58:47 +02:00
```
```yaml {% srNumber=2 %}
2023-07-14 14:12:27 +02:00
password: password
2023-04-25 16:58:47 +02:00
```
```yaml {% srNumber=3 %}
2023-07-14 14:12:27 +02:00
hostPort: localhost:27017
2023-04-25 16:58:47 +02:00
```
```yaml {% srNumber=5 %}
2023-07-14 14:12:27 +02:00
# connectionURI: mongodb://username:password@mongodb0 .example.com:27017
2023-04-25 16:58:47 +02:00
```
```yaml {% srNumber=7 %}
2023-07-14 14:12:27 +02:00
# connectionOptions:
# key: value
2023-04-25 16:58:47 +02:00
```
2023-07-14 14:12:27 +02:00
```yaml {% srNumber=6 %}
database: custom_database_name
2023-04-25 16:58:47 +02:00
```
```yaml {% srNumber=9 %}
2023-05-02 11:32:28 +05:30
sourceConfig:
config:
2023-05-02 16:36:52 +05:30
type: DatabaseMetadata
markDeletedTables: true
includeTables: true
includeViews: true
# includeTags: true
# databaseFilterPattern:
# includes:
# - database1
# - database2
# excludes:
# - database3
# - database4
# schemaFilterPattern:
# includes:
# - schema1
# - schema2
# excludes:
# - schema3
# - schema4
# tableFilterPattern:
# includes:
# - users
# - type_test
# excludes:
# - table3
# - table4
2023-04-25 16:58:47 +02:00
```
```yaml {% srNumber=10 %}
sink:
type: metadata-rest
config: {}
```
2023-08-25 08:49:58 +02:00
{% partial file="/v1.1.2/connectors/workflow-config-yaml.md" /%}
2023-04-25 16:58:47 +02:00
{% /codeBlock %}
{% /codePreview %}
### 2. Run with the CLI
First, we will need to save the YAML file. Afterward, and with all requirements installed, we can run:
```bash
metadata ingest -c < path-to-yaml >
```
Note that from connector to connector, this recipe will always be the same. By updating the YAML configuration,
you will be able to extract metadata from different sources.
## Related
{% tilesContainer %}
{% tile
title="Ingest with Airflow"
description="Configure the ingestion using Airflow SDK"
2023-07-14 14:12:27 +02:00
link="/connectors/database/mongodb/airflow"
2023-04-25 16:58:47 +02:00
/ %}
{% /tilesContainer %}