amoghrajesh commented on PR #37214:
URL: https://github.com/apache/airflow/pull/37214#issuecomment-1931686673

   > > That tip saved hassle for me, ran it via docker compose and it worked :D
   > 
   > Yeah in breeze only available simple integration, which need to be run 
with `--integration mongo`, e.g.
   > 
   > ```
   > ❯ breeze start-airflow --backend postgres --postgres-version 15 
--integration mongo
   > ```
   > 
   > After that you could communicate with Mongo 3 thought the host `mongo`
   > 
   > ```python
   > from airflow import DAG
   > from airflow.decorators import task
   > from airflow.providers.mongo.hooks.mongo import MongoHook
   > 
   > 
   > with DAG("pr_37214", schedule=None, tags=["37214", "mongodb"]):
   >     @task
   >     def test_mongo():
   >         # Create a connection into the runtime, might be replaced by 
connection created into the UI
   >         import os
   >         from airflow.models.connection import Connection
   > 
   >         mongo_conn_id = "mongo_test"
   >         conn = Connection(conn_id=mongo_conn_id, conn_type="mongo", 
host="mongo", port=27017, schema="test")
   >         os.environ[f"AIRFLOW_CONN_{conn.conn_id.upper()}"] = conn.as_json()
   > 
   >         # Actual execution
   >         mongo_hook = MongoHook(mongo_conn_id=mongo_conn_id)
   >         mongo_hook.insert_one("users", {"name": "John", "surname": 
"Wick"}, mongo_db="test")
   > 
   >         collection = mongo_hook.get_collection("users", mongo_db="test")
   >         print(collection.count_documents({}))
   > 
   >     test_mongo()
   > ```
   > 
   > And it is expected that if you try to communicate in breeze with 
`localhost` or `127.0.0.1` that is not exists, because there is no mongo in 
Airflow Breeze container
   
   Perfect! I wasn't aware of this, thank you!
   This is good :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to