更新neo4j節點信息


將多個屬性的內容更新到節點上

def update_by_id(id,graph,**kwargs):
    """
    更新節點的屬性
    根據節點的ID來更新節點的屬性,如果存在該屬性,則更新,如果不存在該屬性,則添加
    """
    if graph is None:
        graph = get_graph()
    if kwargs is None:
        return None
    match = "match (x) where id(x)=%s " % (id)
    fields_str=''
    for k,v in kwargs:
        if v is not None:
            temp = " set x.%s = '%s' " % (k,v)
            fields_str += temp

    match = match + fields_str
    match = match + " return id(x) as x_id"
    result = graph.run(match).data()
    if result is not None and len(result > 0):
        id = result[0]["x_id"]
        return id
    return None

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM