关于apoc.refactor.MergeNodes()配置及参数测试的技术咨询
apoc.refactor.mergeNodes with the {id:'discard'} Parameter Let’s break down exactly how this parameter works and what happens to gtag.id in your scenario:
First, to ground this in your test setup:
You created two tag nodes (
id: "h"andid: "H"), then ran a merge query targeting these nodes withapoc.refactor.mergeNodes([htag, gtag], {id:'discard'}). You’re curious about the parameter’s role and howgtag.idis handled.
What does {id:'discard'} do?
The apoc.refactor.mergeNodes function uses property-specific strategies to resolve conflicts when merging multiple nodes. For the id property here:
- The
'discard'strategy tells APOC to keep the property value from the first node in your input array (in your case,htagwithid: "h"), and completely ignore the same property from all subsequent nodes in the list (here,gtagwithid: "H").
Your initial understanding is on the right track—this does retain htag.id if it exists—but it’s more precise: it unconditionally prioritizes the first node’s value, discarding any matching properties from later nodes in the merge sequence, regardless of their content.
How is gtag.id processed?
In your query:
- The merge array is ordered
[htag, gtag], sohtagacts as the "base" node, andgtagis merged into it. - Since
id:'discard'is specified,gtag.id("H") is discarded entirely. It won’t appear in the final merged node, and it won’t overwritehtag.idat all.
The end result is a single tag node with id: "h", plus any other properties originally on htag. All relationships that were connected to gtag will be transferred to this merged node, and gtag itself will be deleted from the graph.
Quick Context on Other Common Strategies
For reference, here are other property strategies you might use with apoc.refactor.mergeNodes:
'overwrite': Uses the property value from the last node in the array (overwrites earlier values)'combine': Collects all values from merged nodes into a single list'sum'/'min'/'max': Aggregates numeric values using the specified operation
内容的提问来源于stack exchange,提问作者Scofflaw

