code: def get_collection_documents_generator(client, database_name, collection_name, spec, latest_n, sort_key):
      
      mongo_database = client[database_name]
      collection = mongo_database[collection_name]
      collection.create_index(sort_key)
  
      if latest_n is not None:
          skip_n = collection.count() - latest_n
          if collection.count() - latest_n < 0:
              skip_n = 0
          cursor = collection.find(filter=spec).sort([(sort_key, ASCENDING), ])
          cursor = cursor[skip_n:]
      else:
          cursor = collection.find(filter=spec).sort([(sort_key, ASCENDING), ])
  
      for document in cursor:
          yield document
docs: This is a python generator that yields tweets stored in a mongodb collection.
  
      Tweet "created_at" field is assumed to have been stored in the format supported by MongoDB.
  
      Inputs: - client: A pymongo MongoClient object.
              - database_name: The name of a Mongo database as a string.
              - collection_name: The name of the tweet collection as a string.
              - spec: A python dictionary that defines higher query arguments.
              - latest_n: The number of latest results we require from the mongo document collection.
              - sort_key: A field name according to which we will sort in ascending order.
  
      Yields: - document: A document in python dictionary (json) format.