Example #1
0
    def execute(self, context):
        mongo = MongoHook(conn_id=self.conn_id, )
        mongo.uri, dbname = mongo.uri.rsplit("/", maxsplit=1)
        # conn = mongo.get_conn()

        # return conn.list_database_names()

        posts = mongo.get_collection("posts", dbname)

        import datetime
        post = {
            "author": "Mike",
            "text": "My first blog post!",
            "tags": ["mongodb", "python", "pymongo"],
            "date": datetime.datetime.utcnow()
        }
        # posts = db.posts
        post_id = posts.insert_one(post).inserted_id
        # collection = mongo.get_collection('people', mongo_db='starwars')
        # res = collection.find_one()
        # return str(res['_id'])
        return str(post_id)
        'B': dictObj2
    }
    reorderedDictWithReorderedListsInValue = {
        'B': dictObj2,
        'A': [{
            'Y': 2
        }, {
            'X': [reorderedDictObj, dictObj2]
        }]
    }
    a = {"L": "M", "N": dictWithListsInValue}
    b = {"L": "M", "N": reorderedDictWithReorderedListsInValue}

    # return j1, j2
    # return j3,j4
    # return a,b
    r1 = {"1": j1, "2": j3, "3": a}
    r2 = {"1": j2, "2": j4, "3": b}
    return r1, r2


if __name__ == '__main__':
    mongo_hk = MongoHook()
    mongo_hk.uri = 'mongodb://localhost:27017/'
    r1, r2 = genTwoCase()
    a = DataCompareOperator(runner_conf='1',
                            task_id='11',
                            task_id_list=['a', 'b'])
    res = a.record_compare(r1, r2)
    print(res)
# myclient = pymongo.MongoClient("mongodb://localhost:27017/")