Skip to content

Instantly share code, notes, and snippets.

@valiantone
Forked from gghez/mongodb_hook.py
Created April 17, 2018 12:23
Show Gist options
  • Save valiantone/e12f79efc19acbfe3d7b897e3241d983 to your computer and use it in GitHub Desktop.
Save valiantone/e12f79efc19acbfe3d7b897e3241d983 to your computer and use it in GitHub Desktop.
MongoDB Hook for Airflow system.
from airflow.hooks.base_hook import BaseHook
from pymongo import MongoClient
class MongoDBHook(BaseHook):
def __init__(self, conn_id='mongodb_default'):
self.conn = self.get_connection(conn_id)
self.client = MongoClient(host=self.conn.host, port=self.conn.port)
def __getattr__(self, name):
return getattr(self.client, name)
def __getitem__(self, item):
return self.client[item]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment