def _get_last_doc_ref(path, doc):
    """Mutate a document top-down using a path.

    :param pathlib.Path path: The path.
    :param dict doc: The document.
    :rtype: dict
    """
    for part in path.parts:
        if part not in doc:
            doc[part] = {}
        doc = doc[part]
    return doc