Skip to main content

Upsert Nodes using UpsertN  

Create new nodes or update existing ones with insert-or-update semantics.
UpsertN is a traversal step that operates on an existing traversal context. The type comes from the preceding traversal (N<Type>), not from the upsert call itself. If the traversal returns existing nodes, they are updated; if no nodes are found, a new node is created.
When using the SDKs or curling the endpoint, the query name must match what is defined in the queries.hx file exactly.

Example 1: Basic node upsert with properties

Here’s how to run the query using the SDKs or curl

Example 2: Upsert from a pre-fetched node by ID

When you already have a node ID, you can fetch it directly and apply the upsert.
Here’s how to run the query using the SDKs or curl

Example 3: Upsert with WHERE filter

Find existing nodes with a WHERE clause and update or create if not found.
Here’s how to run the query using the SDKs or curl

How Upsert differs from Add and Update

When updating, UpsertN merges properties: it updates specified properties while preserving any existing properties that aren’t included in the upsert.