import logging


def get_requests_raw(db, query):
    """Return a cursor for iterating over agencies' request documents.

    Parameters
    ----------
    db : MongoDatabase
        The Mongo database from which agency data can be retrieved.

    query : dict
        The query to perform.

    Returns
    -------
    pymongo.cursor.Cursor: A cursor that can be used to iterate over
    the request documents.

    Throws
    ------
    pymongo.errors.TypeError: If unable to connect to the requested
    server.

    pymongo.errors.InvalidOperation: If the cursor has already been
    used.

    """
    projection = {
        "_id": True,
        "agency.acronym": True,
        "agency.contacts.name": True,
        "agency.contacts.email": True,
        "agency.contacts.type": True,
    }

    try:
        requests = db.requests.find(query, projection)
    except TypeError:
        logging.critical(
            "There was an error with the MongoDB query that retrieves the request documents",
            exc_info=True,
        )
        raise

    return requests