# Neo4j Connection

**URL:** <https://discourse.julialang.org/t/neo4j-connection/95031>\
**Category:** General Usage\
**Tags:** neo4j\
**Created:** [February 22, 2023, 5:23pm UTC](https://discourse.julialang.org/t/neo4j-connection/95031 "2023-02-22T17:23:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergeantMike67](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergeantmike67/32/25103_2.png) [@SergeantMike67](https://discourse.julialang.org/u/SergeantMike67)\
**Post date:** [February 22, 2023, 5:23pm UTC](https://discourse.julialang.org/t/neo4j-connection/95031/1 "2023-02-22T17:23:17Z")

</div>

Does anybody have experience trying to connect with a Neo4j database on a port other than the default provided for in Neo4j.jl? I can’t make heads or tails of it and Julia keeps yelling at me that I am doing it wrong, which I am.

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [February 23, 2023, 11:42am UTC](https://discourse.julialang.org/t/neo4j-connection/95031/2 "2023-02-23T11:42:59Z")

</div>

I stopped using `neo4j.jl` as I found it buggy and use `cypher-shell` instead which is quite reliable albeit slow.  
You can try it out with:  
`cypher-shell -a neo4j://localhost:7687 --format plain -u USER -p PASSWORD 'match (n) return n'`  
where `-a` specifies the `address:port`. In julia, you can do

```julia
read(`cypher-shell -a neo4j://localhost:7687 --format plain -u USER -p PASSWORD 'match (n) return n'`, String)

```

and process manually the resulting string

---

<div class="post-metadata">

**Author:** ![SergeantMike67](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergeantmike67/32/25103_2.png) [@SergeantMike67](https://discourse.julialang.org/u/SergeantMike67)\
**Post date:** [February 23, 2023, 2:38pm UTC](https://discourse.julialang.org/t/neo4j-connection/95031/3 "2023-02-23T14:38:07Z")

</div>

> [@zgornel](#):
>
> `read(`cypher-shell -a neo4j://localhost:7687 --format plain -u USER -p PASSWORD ‘match (n) return n’`, String)`

This works great thank you. Not so much worried about speed here as all I am doing in setting up relationships between nodes and to do them one at a time would have been mind numbingly tedious and the slowest connection is still exponentially faster than me doing it manually.

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [February 23, 2023, 3:00pm UTC](https://discourse.julialang.org/t/neo4j-connection/95031/4 "2023-02-23T15:00:29Z")

</div>

Great 😉 Apparently `cyper-shell` supports scripts as well. More on [here](https://stackoverflow.com/questions/56038659/how-to-run-a-cypher-script-file-from-terminal-with-the-cypher-shell-neo4j-comman) and [here](https://stackoverflow.com/questions/17462306/how-to-execute-cypher-in-a-file). I’m using it as well one command at a time - unfortunately it can become quite slow for even small graphs (i.e. tens/hundreds of links).

---

<div class="post-metadata">

**Author:** ![SergeantMike67](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergeantmike67/32/25103_2.png) [@SergeantMike67](https://discourse.julialang.org/u/SergeantMike67)\
**Post date:** [February 26, 2023, 9:33pm UTC](https://discourse.julialang.org/t/neo4j-connection/95031/5 "2023-02-26T21:33:26Z")

</div>

I’ve been banging my head here about how to create relationships progammatically through Julia.

lets say:  
pollen = “Sooy”  
offspring = " Pioneer"  
and I want to create a relationship in Neo4j called Pollen between Sooy and Pioneer, one way.

the query is  
‘MATCH (a.Names),(b.Names)  
WHERE a.Cultivar = “Sooy” AND b.Culitvar = “Pioneer”  
CREATE (a)-[r:Pollen]-\>(b)  
RETURN a,b’

which is all well and good but I have over 200 of these relationships to create with the names stored in a CSV file. My idea is to load the CSV file into a DataFrame and then iterate through each offspring and create a relationship to the pollen parent and the seed parent. This would require me to use

WHERE a.Cultivar = "(seed)\" AND "b.Cultivar = \"(offspring)" since I need to use interpolation. Any ideas on how to pull this off?

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [February 27, 2023, 5:08pm UTC](https://discourse.julialang.org/t/neo4j-connection/95031/6 "2023-02-27T17:08:30Z")

</div>

What I do in my usecases is to construct all `neo4j` statements and run them in parallel.

In the case you provided, you could do something similar to the (incomplete) example below (you can also use a `DataFrame` as you mentioned)

```julia
function preprocess_line(line)
   # preprocess one line of the csv file and extract 'pollen' and 'cultivat'
   return (pollen, cultivar) # Tuple{String,String}
end

# Generate a vector of 'MATCH' statements
statements = ["MATCH ... where a.Cultivar=$pollen AND b.Cultivar=$offspring CREATE ..."
                         for (pollen, cultivar) in preprocess_line(eachline(csvfile))]

# Run statements in parallel
@sync for stmt in statements
  @async run(`cypher-shell --format plain -u $USER -p $PASSWORD $stmt`, wait=true);
end
```
