Bolt

Bolt procedures allows to accessing other databases via bolt protocol.

CALL apoc.bolt.execute(urlOrKey, statement, params, config) YIELD row

access to other databases via bolt for read and write

CALL apoc.bolt.load(urlOrKey, statement, params, config) YIELD row

access to other databases via bolt for read

CALL apoc.bolt.fromLocal(urlOrKey, localStatement, remoteStatement, config) YIELD row

executes the localStatement on the local instance and uses the results a parameters for the remoteStatement executed on the remote instance

urlOrKey param allows users to decide if send url by apoc or if put it into apoc.conf file.

  • apoc : write the complete url in his right position on the apoc.

call apoc.bolt.load("bolt://user:password@localhost:7687","match(p:Person {name:{name}}) return p", {name:'Michael'})
  • apoc.conf : here the are two choices:

1) complete url: write the complete url with the param apoc.bolt.url;

apoc
call apoc.bolt.load("","match(p:Person {name:{name}}) return p", {name:'Michael'})
neo4jConf
//simple url
apoc.bolt.url=bolt://user:password@localhost:7687

2) by key: set the url with a personal key apoc.bolt.yourKey.url; in this case in the apoc on the url param user has to insert the key.

apoc
call apoc.bolt.load("test","match(p:Person {name:{name}}) return p", {name:'Michael'})
neo4jConf
//with key
apoc.bolt.test.url=bolt://user:password@localhost:7687
apoc.bolt.production.url=bolt://password:test@localhost:7688

Config available are:

  • statistics: possible values are true/false, the default value is false. This config print the execution statistics;

  • virtual: possible values are true/false, the default value is false. This config return result in virtual format and not in map format, in apoc.bolt.load.

  • databaseName: the database instance name on the remote Neo4j instance

  • streamStatements: if true and used in combination with the cypher export procedures it streams the statement from local to remote database.

Driver configuration

To set the configuration of the Driver, you can add the parameter driverConfig in the config. Is’s a map of values, the values that we don’t pass to the config, are set to the default value.

{logging='INFO', encryption=true, logLeakedSessions:true, maxIdleConnectionPoolSize:10, idleTimeBeforeConnectionTest:-1, trustStrategy:'TRUST_ALL_CERTIFICATES',
 routingFailureLimit: 1, routingRetryDelayMillis:5000, connectionTimeoutMillis:5000, maxRetryTimeMs:30000 }
param description possible values/ types

logging

logging provider to use

INFO, WARNING, OFF, SEVERE, CONFIG, FINE, FINER

encryption

Disable or enabled encryption

true, false

logLeakedSessions

Disable or enable logging of leaked sessions

true, false

maxIdleConnectionPoolSize

Max number of connections

number

idleTimeBeforeConnectionTest

Pooled connections that have been idle in the pool for longer than this timeout

Milliseconds

trustStrategy

Specify how to determine the authenticity of an encryption certificate provided by the Neo4j instance we are connecting to

TRUST_ALL_CERTIFICATES, TRUST_SYSTEM_CA_SIGNED_CERTIFICATES, or directly a custom certificate

routingFailureLimit

the number of times to retry each server in the list of routing servers

number

routingRetryDelayMillis

Specify how long to wait before retrying to connect to a routing server

Milliseconds

connectionTimeoutMillis

Specify socket connection timeout

Milliseconds

maxRetryTimeMs

Specify the maximum time transactions are allowed to retry

Milliseconds

You can find all the values in the documentation Config.ConfigBuilder

Bolt Examples

Return node in map format

call apoc.bolt.execute("bolt://user:password@localhost:7687",
"match(p:Person {name:{name}}) return p", {name:'Michael'})
apoc.bolt.execute.nodemap

Return node in virtual Node format

call apoc.bolt.load("bolt://user:password@localhost:7687",
"match(p:Person {name:{name}}) return p", {name:'Michael'}, {virtual:true})
apoc.bolt.load.virtualnode

Create node and return statistic

call apoc.bolt.execute("bolt://user:password@localhost:7687",
"create(n:Node {name:{name}})", {name:'Node1'}, {statistics:true})
apoc.bolt.execute.createandstatistics

Return more scalar values

call apoc.bolt.execute("bolt://user:password@localhost:7687",
"match (n:Person {name:{name}}) return n.age as age, n.name as name, n.surname as surname", {name:'Michael'})
apoc.bolt.execute.scalarmulti

Return relationship in a map format

call apoc.bolt.load("bolt://user:password@localhost:7687",
"MATCH (n:Person{name:{name}})-[r:KNOWS]->(p) return r as rel", {name:'Anne'})
apoc.bolt.load.relmap

Return virtual path

call apoc.bolt.load("bolt://user:password@localhost:7687",
"START n=node({idNode}) MATCH path= (n)-[r:REL_TYPE*..3]->(o) return path", {idNode:200}, {virtual:true})
apoc.bolt.load.returnvirtualpath

Create a Node with params in input

call apoc.bolt.execute("bolt://user:password@localhost:7687",
"CREATE (n:Car{brand:{brand},model:{model},year:{year}}) return n", {brand:'Ferrari',model:'California',year:2016})
apoc.bolt.execute.createwithparams