patch to_key in documents