I'm using Neo4J Javascript Driver to query database from my Node.Js app.
Suppose I use the following construct to send several queries to Neo4J (looping through them).
When do I need to close the session and when do I need to close the driver?
Shall I do it in the end of every cycle (as below) or after all the cycles are complete? If it's the latter, how would I do that?
And another question — do I really have to close the driver? What if my app runs continuously? What if it quits because of some error and restarts again?
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
var session = driver.session();
var transactionQueries = ['MATCH ...', 'MATCH ...'];
for (var key in transactionQueries) {
session
.run(transactionQueries[key])
.subscribe({
onNext: function (record) {
console.log(record.get('name'));
},
onCompleted: function () {
session.close();
},
onError: function (error) {
console.log(error);
}
});
}
driver.close();
In my opinion, I think you can keep the connection (driver) but the session should be opened and closed like the instructions on
neo4j-javascript-driverOther think that I suggest to you is see if one OGM help you to code better like
neo4j-node-ogm