Bolt

Bolt procedures allows to accessing other databases via bolt protocol.

Qualified Name Type Release

apoc.bolt.execute

apoc.bolt.execute(url-or-key, kernelTransaction, params, config) - access to other databases via bolt for reads and writes

Procedure

APOC Full

apoc.bolt.load

apoc.bolt.load(url-or-key, kernelTransaction, params, config) - access to other databases via bolt for read

Procedure

APOC Full

apoc.bolt.load.fromLocal

``

Procedure

APOC Full

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. The default value is 'neo4j'. Put null to connect through protocol which not support database name (for neo4j before 4.x).

In addition, the apoc.bolt.load.fromLocal can have: * streamStatements: if true and used in combination with the cypher export procedures it streams the statement from local to remote database. * readOnly: default false. To execute or not, read-only statements. * localParams: to put optional parameters to local cypher statement

Install Dependencies

The Bolt procedures have dependencies on a client library that is not included in the APOC Library.

You can download it from mvnrepository or apoc repository. Once that file is downloaded, it should be placed in the plugins directory and the Neo4j Server restarted.

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}) set p.surname = $surname return p",
{name:'Michael', surname: 'Jordan'})
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}) set n.foo = 'bar' return n.age as age, n.name as name, n.surname as surname, n.foo as foo", {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",
"MATCH (n) WHERE id(n) = $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