Chapter 3 Connection

3.1 HTTP connection

You can start a new connection to your server with the neo4j_api object.

You’ll need to call neo4j_api$new, with the url (with port specified if any), your user name, and your password.

library(neo4r)
con <- neo4j_api$new(
  url = "http://localhost:7474",
  user = "neo4j", 
  password = "password"
  )

If you don’t want your password to be included in the script, you can use the rstudioapi::askForPassword() function, which will open a little widget asking to interactively enter your password.

con <- neo4j_api$new(
  url = "http://localhost:7474",
  user = "neo4j", 
  password = rstudioapi::askForPassword()
  )

You can then check if you can access to the server by pinging it:

con$ping()
## [1] 200

Which should return 200 if the connexion succeeded.

3.2 Get informations about the connection :

You’ll then be able to get information about the server with:

# Get Neo4J Version
con$get_version()
## [1] "3.5.5"
# List constaints (if any)
con$get_constraints()
## Null data.table (0 rows and 0 cols)
# Get a table of labels (if any)
con$get_labels()
## # A tibble: 2 x 1
##   labels
##   <chr> 
## 1 Movie 
## 2 Person
# Get a table of relationships (if any)
con$get_relationships()
## # A tibble: 6 x 1
##   labels  
##   <chr>   
## 1 ACTED_IN
## 2 DIRECTED
## 3 PRODUCED
## 4 WROTE   
## 5 FOLLOWS 
## 6 REVIEWED
# Get index 
con$get_index()
## Null data.table (0 rows and 0 cols)