Skip to content

Instantly share code, notes, and snippets.

@gghez
Created July 26, 2017 08:09
Show Gist options
  • Save gghez/eabb9407ed1659d1633731d349d725d7 to your computer and use it in GitHub Desktop.
Save gghez/eabb9407ed1659d1633731d349d725d7 to your computer and use it in GitHub Desktop.

Revisions

  1. gghez created this gist Jul 26, 2017.
    14 changes: 14 additions & 0 deletions mongodb_hook.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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]