The Neo4j JavaScript driver's session object has a readTransaction method that you can use for marking read queries explicitly.
For Version 4 of the driver, the below example using the readTransaction function is correct:
var movieName = 'matrix'
const readQuery = `MATCH (p:Person)-[:ACTED_IN]->(m)\
WHERE toLower(m.title) CONTAINS toLower($title) \
RETURN DISTINCT p.name as actorsTx`
const readResult = await session.readTransaction(tx =>
tx.run(readQuery, { title: movieName })
)
readResult.records.forEach(record => {
console.log(`Found actor: ${record.get('actorsTx')}`)
})
For Version 5 of the driver, you need to use the executeRead function instead:
var movieName = 'matrix'
const readQuery = `MATCH (p:Person)-[:ACTED_IN]->(m)\
WHERE toLower(m.title) CONTAINS toLower($title) \
RETURN DISTINCT p.name as actorsTx`
const readResult = await session.executeRead(tx =>
tx.run(readQuery, { title: movieName })
)
readResult.records.forEach(record => {
console.log(`Found actor: ${record.get('actorsTx')}`)
})
Comments
0 comments
Please sign in to leave a comment.