def retrieve_tweets(mode="collection"): collection_name = get_collection_name(mode) tweets_cursor = get_mongo_db_collection(DATABASE_NAME, collection_name["tweets"]).find() tweets = [] for tweet in tweets_cursor: tweets.append(tweet) return tweets
def setup_collection(db_name, collection_name): """ Sets up the collection by creating an index for it if it doesn't exist :param db_name: name of the database :param collection_name: name of the collection :return: the collection """ collection = get_mongo_db_collection(db_name, collection_name) if len(collection.index_information()) < 2: collection.create_index([('id', ASCENDING)], unique=True) return collection
def update_tweet(tweet_id, tweet_field_to_value, mode="collection"): collection_name = get_collection_name(mode) collection = get_mongo_db_collection(DATABASE_NAME, collection_name["tweets"]) collection.update_one({'id': tweet_id}, {"$set": tweet_field_to_value})
def fetch_tweet_by_id(tweet_id, mode="collection"): collection_name = get_collection_name(mode) tweet_cursor = get_mongo_db_collection( DATABASE_NAME, collection_name["tweets"]).find({'id': tweet_id}) tweets = [tweet for tweet in tweet_cursor] return tweets
def fetch_user_by_id(user_id, mode="collection"): collection_name = get_collection_name(mode) user_cursor = get_mongo_db_collection( DATABASE_NAME, collection_name["users"]).find({'id': user_id}) users = [user for user in user_cursor] return users
def fetch_all_places(mode="ugtweets"): collection_name = get_collection_name(mode) place_cursor = get_mongo_db_collection(DATABASE_NAME, collection_name["places"]).find({}) places = [place for place in place_cursor] return places
def fetch_all_users(mode="collection"): collection_name = get_collection_name(mode) user_cursor = get_mongo_db_collection(DATABASE_NAME, collection_name["users"]).find({}) users = [user for user in user_cursor] return users