Neo4j with the JavaScript driver
Uses neo4j-driver 6.3. The code is an ordinary application for the original database; nothing in it knows about MachNoSQL.
The only change
Section titled “The only change”neo4j://neo4j.example.com:7687neo4j://machnosql.example.com:7687The address comes from the environment variable NEO4J_URI, so switching to MachNoSQL changes configuration only.
export NEO4J_URI='neo4j://machnosql.example.com:7687'npm installnpm startCredentials come from NEO4J_USERNAME and NEO4J_PASSWORD.
Source
Section titled “Source”The program as it is kept and tested in the Mach Database NoSQL repository; highlighted lines read the connection setting.
// Friends of friends on Neo4j, unchanged on MachNoSQL.import neo4j from "neo4j-driver";
const driver = neo4j.driver( process.env.NEO4J_URI, neo4j.auth.basic(process.env.NEO4J_USERNAME, process.env.NEO4J_PASSWORD),);await driver.verifyConnectivity();
await driver.executeQuery( "UNWIND $pairs AS pair MERGE (a:Person {name: pair[0]}) MERGE (b:Person {name: pair[1]}) MERGE (a)-[:KNOWS]->(b)", { pairs: [["ada", "grace"], ["grace", "linus"], ["grace", "margaret"], ["linus", "ken"]] },);const { records } = await driver.executeQuery( "MATCH (p:Person {name: $name})-[:KNOWS]->()-[:KNOWS]->(fof) WHERE fof <> p RETURN DISTINCT fof.name AS name ORDER BY name", { name: "ada" },);console.log(records.map((record) => record.get("name")));
await driver.close();{ "name": "machnosql-example-neo4j-node", "private": true, "type": "module", "scripts": { "start": "node app.js" }, "dependencies": { "neo4j-driver": "^6.3.0" }}