Neo4j with the .NET driver
Uses Neo4j.Driver 6.4 on .NET 10. 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'dotnet runCredentials 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.using Neo4j.Driver;
await using var driver = GraphDatabase.Driver( Environment.GetEnvironmentVariable("NEO4J_URI"), AuthTokens.Basic(Environment.GetEnvironmentVariable("NEO4J_USERNAME"), Environment.GetEnvironmentVariable("NEO4J_PASSWORD")));await driver.VerifyConnectivityAsync();
var pairs = new[] { new[] { "ada", "grace" }, new[] { "grace", "linus" }, new[] { "grace", "margaret" }, new[] { "linus", "ken" } };await driver.ExecutableQuery("UNWIND $pairs AS pair MERGE (a:Person {name: pair[0]}) MERGE (b:Person {name: pair[1]}) MERGE (a)-[:KNOWS]->(b)") .WithParameters(new { pairs }) .ExecuteAsync();
var result = await driver.ExecutableQuery("MATCH (p:Person {name: $name})-[:KNOWS]->()-[:KNOWS]->(fof) WHERE fof <> p RETURN DISTINCT fof.name AS name ORDER BY name") .WithParameters(new { name = "ada" }) .ExecuteAsync();foreach (var record in result.Result){ Console.WriteLine(record["name"].As<string>());}<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net10.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> </PropertyGroup> <ItemGroup> <PackageReference Include="Neo4j.Driver" Version="6.4.0" /> </ItemGroup></Project>