# How to set Property in the existing Node through Spark datasource

**URL:** https://community.neo4j.com/t/how-to-set-property-in-the-existing-node-through-spark-datasource/73654
**Category:** Cypher
**Tags:** browser, cypher
**Created:** [April 26, 2025, 9:15am UTC](https://community.neo4j.com/t/how-to-set-property-in-the-existing-node-through-spark-datasource/73654 "2025-04-26T09:15:21Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![palak.joshi](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/palak.joshi/32/32673_2.png) [@palak.joshi](https://community.neo4j.com/u/palak.joshi)
#### Post date: [April 26, 2025, 9:15am UTC](https://community.neo4j.com/t/how-to-set-property-in-the-existing-node-through-spark-datasource/73654/1 "2025-04-26T09:15:21Z")

</div>

I have already created node and relationships through spark datasource like this :-

val relationshipConfig = Map(  
"CONNECTED" -\> ("PostalCode", "Prefecture", "PostalCode", "Prefecture")  
)

```
  // FUNCTION TO CREATE RELATIONSHIPS & NODES
  def writeToNeo4j(
                    finalData: DataFrame,
                    relationship: String,
                    sourceColumn: String,
                    targetColumn: String,
                    sourceLabel: String,
                    targetLabel: String,
                    url: String,
                    username: String,
                    password: String
                  ): Unit = {
    
      println(s"Writing relationship: $relationship from $sourceLabel to $targetLabel")

      finalData.select(sourceColumn, targetColumn).distinct().write
        .mode("Append")
        .format("org.neo4j.spark.DataSource")
        .option("relationship", relationship)
        .option("relationship.save.strategy", "keys")
        .option("relationship.source.node.keys", s"$sourceColumn")
        .option("relationship.target.node.keys", s"$targetColumn")
        .option("relationship.merge", "true") // Important: Use merge for relationships
        .option("relationship.source.save.mode", "Append")
        .option("relationship.source.labels", s":$sourceLabel")
        .option("relationship.source.node.properties", s"$sourceColumn")
        .option("relationship.target.save.mode", "Append")
        .option("relationship.target.labels", s":$targetLabel")
        .option("relationship.target.node.properties", s"$targetColumn")
        .option("url", url)
        .option("authentication.type", "basic")
        .option("authentication.basic.username", username)
        .option("authentication.basic.password", password)
        .save()

        relationshipConfig.foreach { case (relationship, (sourceLabel, 
        targetLabel, sourceColumn, targetColumn)) =>
        writeToNeo4j(finalData, relationship, sourceColumn, targetColumn, 
        sourceLabel, targetLabel, url, username, password)
   }

```

So in my neo4j browser i have two nodes PostalCode and Prefecture and having relationship between both.

`now the case is i want to add property in node PostalCode. How i can do that? How i can modify my this code or add a function to update node to add property? `

I have saw this cypher query.

```auto
MATCH (n:PostalCode)
SET n.City = 'xyz'
RETURN n

```

but I want a solution correspond to this in spark datasource.

@conker84  
Any help would be really Appreciated!  
Thanks.
