TenTonBonton
TenTonBonton

Reputation: 119

How to insert nodes with labels and aroperties in Python client for Memgraph

I've been trying to figure out how to use a Python client to insert nodes into my graph database. I need to add nodes that might already exist or might not exist yet, along with their labels and properties.

I've gone through the Memgraph documentation, but I couldn't find a clear answer on how to do this.

Here's what I'm trying to achieve:

  1. Check if a node exists.
  2. If it does, update its properties.
  3. If it doesn't, create the node with specific labels and properties.

Upvotes: 1

Views: 58

Answers (1)

Zet Hund Pet
Zet Hund Pet

Reputation: 120

MERGE with ON CREATE SET and ON MATCH SET should do the trick. It allows you to update object differently depending on whether they exist or not. If that object doesn't exist, then it triggers ON CREATE (because it needs to be created). On the other hand, if the object already exists, then it's being matched so it triggers ON MATCH SET.

Upvotes: 1

Related Questions