更新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