def get_db(db_name): from pymongo import MongoClient client = MongoClient('localhost:27017') db = client[db_name] return db def make_pipeline(): pipeline = [ ] return pipeline def aggregate(db, pipeline): return [doc for doc in db.tweets.aggregate(pipeline)] if __name__ == '__main__': db = get_db('twitter') pipeline = make_pipeline() result = aggregate(db, pipeline) import pprint assert len(result) == 1 assert result[0]["followers"] == 17209