You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于apoc.refactor.MergeNodes()配置及参数测试的技术咨询

Understanding 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" and id: "H"), then ran a merge query targeting these nodes with apoc.refactor.mergeNodes([htag, gtag], {id:'discard'}). You’re curious about the parameter’s role and how gtag.id is 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, htag with id: "h"), and completely ignore the same property from all subsequent nodes in the list (here, gtag with id: "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], so htag acts as the "base" node, and gtag is 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 overwrite htag.id at 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:41:06