Neo4j Add/update properties if node exists

前端 未结 3 1659
陌清茗
陌清茗 2020-12-29 08:11

I want to be able to update/enlarge my Neo4j database by uploading a newer version of that database OR part of that database.

Of what I\'ve found I can

3条回答
  •  佛祖请我去吃肉
    2020-12-29 08:30

    MERGE guarantees that a node will exist afterwards (either matched or created). If you don't want to create the node, you need to use MATCH instead. (Since you say "if node exists", that implies it shouldn't be created)

    The simplest way is

    MATCH (n{id:{uuid}) SET n.prop=true
    

    If the match fails, their will be nothing to do the SET against.

    Assuming that you would like to still have rows after; (for a more complex query) You can just make the match optional

    ...
    OPTIONAL MATCH (n{id:{uuid}) SET n.prop=true
    

    Again, if the match fails, n will be null, and the SET will do nothing

提交回复
热议问题