0
votes

In the recent version of Neo4j-Spark connector (4.0.0) there is an example in the official documentation which demonstrates reading from Neo4j using spark (here):

import org.apache.spark.sql.{SaveMode, SparkSession}

val spark = SparkSession.builder().getOrCreate()

spark.read.format("org.neo4j.spark.DataSource")
  .option("url", "bolt://localhost:7687")
  .option("labels", "Person")
  .load()
  .show()

Imagine i have several databases running on "bolt://localhost:7687". I wonder how i can specify the database name which i want to read the data from. Does this connector even supports this kind of transaction?

1

1 Answers

3
votes

In the driver configuration section https://neo4j.com/developer/spark/configuration/ you can find that the option database is used to specify the db to use :

spark.read.format("org.neo4j.spark.DataSource")
  .option("url", "bolt://localhost:7687")
  .option("database", "mydb")
  .option("labels", "Person")
  .load()
  .show()

You can also find the source code for that option here : https://github.com/neo4j-contrib/neo4j-spark-connector/blob/4.0/src/main/scala/org/neo4j/spark/Neo4jOptions.scala#L83