cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Can anyone tell me where in the documentation I found this!

This is crazy but the following code seemed to work well when I ran it a couple of weeks ago - now I am returning to study it more closely but I can't find it again in the documentation! Does anyone recognise it please??

//
const person1Name = 'Alice'
const person2Name = 'David'

try {
// To learn more about the Cypher syntax, see The Neo4j Cypher Manual v4.3 - Neo4j Cypher Manual
// The Reference Card is also a good resource for keywords Neo4j Cypher Refcard 4.3
const writeQuery = MERGE (p1:Person { name: $person1Name }) MERGE (p2:Person { name: $person2Name }) MERGE (p1)-[:KNOWS]->(p2) RETURN p1, p2

// Write transactions allow the driver to handle retries and transient errors
const writeResult = await session.writeTransaction(tx =>
tx.run(writeQuery, { person1Name, person2Name })
)
writeResult.records.forEach(record => {
const person1Node = record.get('p1')
const person2Node = record.get('p2')
console.log(
Created friendship between: ${person1Node.properties.name}, ${person2Node.properties.name}
)
})

const readQuery = MATCH (p:Person) WHERE p.name = $personName RETURN p.name AS name
const readResult = await session.readTransaction(tx =>
tx.run(readQuery, { personName: person1Name })
)
readResult.records.forEach(record => {
console.log(Found person: ${record.get('name')})
})
} catch (error) {
console.error('Something went wrong: ', error)
} finally {
await session.close()
}

// Don't forget to close the driver connection when you're finished with it
await driver.close()
})();

2 REPLIES 2

That looks like it's from one of our drivers documentation pages, maybe for .net? You can start here, and select whichever drivers guide looks appropriate. You should find an example like that somewhere around the section about working with sessions and transactions.

I just found it via the history in my browser from two weeks ago ...:-

https://console.neo4j.io/#how-to-connect

javascript tab

Thanks anyway for your trouble.