Bolt
Bolt procedures allows to accessing other databases via bolt protocol.
|
access to other databases via bolt for read and write |
|
access to other databases via bolt for read |
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;
call apoc.bolt.load("","match(p:Person {name: $name}) return p", {name:'Michael'})
//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.
call apoc.bolt.load("test","match(p:Person {name: $name}) return p", {name:'Michael'})
//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.
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'})
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})
Create node and return statistic
call apoc.bolt.execute("bolt://user:password@localhost:7687",
"create(n:Node {name: $name})", {name:'Node1'}, {statistics:true})
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'})
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'})
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})
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})