Search code examples
cyphermemgraphdbopencypher

MemgraphDB: Using openCypher to add names to Karate club friendship network


I'm using Karate club friendship network sample data set to learn Cypher. Here is the description of it:

The model consists of 34 users where some users are friends within a university karate club.

  • User node - A user in the karate club.

    • id - A unique identified for a user (e.g. "1").
    • name - Name of the user which is equal to the id (e.g. "1"). Relationships:
  • FRIENDS_WITH relationship - Connects a User to another User friend.

The description says, and my query confirms that users have no names, they have ID and name the same.

enter image description here

I'd like to change this. How can I update the names of all nodes?


Solution

  • Here is one way:

    UNWIND [['0','Adam'],['1','Bridget'],['2','Charlie'],...,['33','Zoe']] AS data
    MATCH (u:User)
    WHERE u.id = data[0]
    SET u.name = data[1]