{"id":3398,"library":"apache-airflow-providers-mongo","title":"Apache Airflow MongoDB Provider","description":"The `apache-airflow-providers-mongo` package extends Apache Airflow's capabilities by providing operators, hooks, and sensors to interact with MongoDB databases. It enables users to orchestrate various MongoDB operations, such as inserting, updating, deleting, and querying data, directly within their Airflow DAGs. The provider is actively maintained, with frequent releases to support new Airflow versions and add features. The current version is 5.3.4.","status":"active","version":"5.3.4","language":"en","source_language":"en","source_url":"https://github.com/apache/airflow/tree/main/airflow/providers/mongo","tags":["Apache Airflow","MongoDB","ETL","Data Orchestration","Database","Provider"],"install":[{"cmd":"pip install apache-airflow-providers-mongo","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"This is an Airflow provider package and requires a compatible Airflow installation. Version 5.3.4 requires Airflow >=2.11.0.","package":"apache-airflow","optional":false},{"reason":"The underlying Python driver for MongoDB interaction used by MongoHook.","package":"pymongo","optional":false},{"reason":"Required for using DNS seedlist (SRV records) in MongoDB connection strings.","package":"dnspython","optional":true}],"imports":[{"symbol":"MongoHook","correct":"from airflow.providers.mongo.hooks.mongo import MongoHook"},{"symbol":"MongoOperator","correct":"from airflow.providers.mongo.operators.mongo import MongoOperator"},{"symbol":"MongoSensor","correct":"from airflow.providers.mongo.sensors.mongo import MongoSensor"}],"quickstart":{"code":"from __future__ import annotations\n\nimport os\nfrom datetime import datetime\n\nfrom airflow.models.dag import DAG\nfrom airflow.providers.mongo.operators.mongo import MongoOperator\n\n# Configure your MongoDB connection in Airflow UI or via environment variable.\n# Example for environment variable:\n# export AIRFLOW_CONN_MONGODB_DEFAULT='mongo://username:password@host:port/database?authSource=admin'\n# For MongoDB Atlas (SRV record), use extra: {'srv': true, 'ssl': true}\n# Example: export AIRFLOW_CONN_MONGODB_DEFAULT='mongo://username:password@cluster.mongodb.net/?retryWrites=true&w=majority'\n# Then, in Airflow UI, edit the connection and add {\"srv\": true, \"ssl\": true} to the 'Extra' field.\n# The 'Host' should be your cluster name, e.g., 'cluster0.abcde.mongodb.net'\n\nwith DAG(\n    dag_id='mongo_insert_example',\n    start_date=datetime(2023, 1, 1),\n    schedule=None,\n    catchup=False,\n    tags=['mongodb', 'example'],\n    doc_md=\"\"\"### MongoDB Insert Example DAG\n    This DAG demonstrates how to use the MongoOperator to insert a document into a MongoDB collection.\n    Ensure you have an Airflow connection named 'mongodb_default' configured for your MongoDB instance.\n    \"\"\"\n) as dag:\n    insert_document_task = MongoOperator(\n        task_id='insert_sample_document',\n        mongo_conn_id='mongodb_default', # This refers to the Airflow connection ID\n        database='mydatabase',\n        collection='mycollection',\n        operation='insert_one',\n        document={'name': 'Alice', 'age': 30, 'city': 'New York'}\n    )\n","lang":"python","description":"This quickstart demonstrates how to use the `MongoOperator` to insert a single document into a MongoDB collection. It assumes an Airflow connection named `mongodb_default` has been configured in the Airflow UI or via an environment variable. For MongoDB Atlas connections, ensure the 'Extra' field of the Airflow connection is correctly configured for SRV and SSL."},"warnings":[{"fix":"Update all instances of `MongoHook(conn_id=...)` to `MongoHook(mongo_conn_id=...)`.","message":"The `conn_id` parameter in `MongoHook` was removed and replaced by `mongo_conn_id`. Direct usage of `conn_id` will result in errors.","severity":"breaking","affected_versions":">=5.3.4"},{"fix":"Ensure your Airflow environment meets the minimum version requirement for the installed provider package. Upgrade Airflow if necessary.","message":"The minimum supported Apache Airflow version for `apache-airflow-providers-mongo` has consistently increased with provider updates. Version 5.3.4 requires Airflow >=2.11.0. Older provider versions require earlier Airflow versions, e.g., 5.1.0 requires 2.10+, 4.2.0 requires 2.8+, and 4.0.0 requires 2.7+.","severity":"breaking","affected_versions":"All versions, specifically 5.3.4 requires >=2.11.0"},{"fix":"If you explicitly require insecure SSL connections, you must set `allow_insecure: true` in the 'Extra' JSON field of your Airflow MongoDB connection. For secure connections, no action is needed as `allow_insecure` defaults to `False`.","message":"Since provider version 4.0.0, the `allow_insecure` flag in the MongoDB connection's 'Extra' field defaults to `False` when SSL encryption (`ssl=True`) is enabled. This means insecure SSL connections are not permitted by default.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Ensure you are on provider version 4.x or newer if you encounter issues with `ssl=False` and `srv=True` combination. Verify your MongoDB connection string and 'Extra' settings are correctly formed according to PyMongo's and Airflow's documentation.","message":"There was an issue where setting `ssl=False` in the connection 'Extra' field, especially when combined with `srv=True` for DNS seedlists, did not correctly disable SSL/TLS, potentially leading to connection errors. This was noted as fixed in a patch for 4.x versions (related to #37214).","severity":"gotcha","affected_versions":"<4.x (prior to fix for #37214)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}