def get_doc_id(doc):
    """Return the document ID from input.

    :param doc: Document ID or body with "_id" field.
    :type doc: str | unicode | dict
    :return: Document ID.
    :rtype: str | unicode
    :raise arango.exceptions.DocumentParseError: If document ID is missing.
    """
    try:
        return doc['_id'] if isinstance(doc, dict) else doc
    except KeyError:
        raise DocumentParseError('field "_id" required')
def get_col_name(doc):
    """Return the collection name from input.

    :param doc: Document ID or body with "_id" field.
    :type doc: str | unicode | dict
    :return: Collection name.
    :rtype: [str | unicode]
    :raise arango.exceptions.DocumentParseError: If document ID is missing.
    """
    try:
        doc_id = doc['_id'] if isinstance(doc, dict) else doc
    except KeyError:
        raise DocumentParseError('field "_id" required')
    return doc_id.split('/', 1)[0]
示例#3
0
def get_doc_id(doc: Union[str, Json]) -> str:
    """Return the document ID from input.

    :param doc: Document ID or body with "_id" field.
    :type doc: str | dict
    :return: Document ID.
    :rtype: str
    :raise arango.exceptions.DocumentParseError: If document ID is missing.
    """
    try:
        doc_id: str = doc["_id"] if isinstance(doc, dict) else doc
    except KeyError:
        raise DocumentParseError('field "_id" required')
    else:
        return doc_id