Neo4j provides advanced tools to make learning and development of graph applications easier. Free to use and run anywhere.
// npm install --save neo4j-driver
// node example.js
const neo4j = require("neo4j-driver");
const driver = neo4j.driver("bolt://<HOST>:<BOLTPORT>", neo4j.auth.basic("<USERNAME>", "<PASSWORD>"), {
/* encrypted: 'ENCRYPTION_OFF' */
});
const query = `
MATCH (p:Product)-[:PART_OF]->(:Category)-[:PARENT*0..]->
(:Category {categoryName:$category})
RETURN p.productName as product
`;
const params = { category: "Dairy Products" };
const session = driver.session({ database: "neo4j" });
session
.run(query, params)
.then((result) => {
result.records.forEach((record) => {
console.log(record.get("product"));
});
session.close();
driver.close();
})
.catch((error) => {
console.error(error);
});
# pip3 install neo4j-driver
# python3 example.py
from neo4j import GraphDatabase, basic_auth
driver = GraphDatabase.driver(
"bolt://<HOST>:<BOLTPORT>",
auth=basic_auth("<USERNAME>", "<PASSWORD>"))
cypher_query = '''
MATCH (p:Product)-[:PART_OF]->(:Category)-[:PARENT*0..]->
(:Category {categoryName:$category})
RETURN p.productName as product
'''
with driver.session(database="neo4j") as session:
results = session.read_transaction(
lambda tx: tx.run(cypher_query,
category="Dairy Products").data())
for record in results:
print(record['product'])
driver.close()
// go mod init main
// go run example.go
package main
import (
"fmt"
"github.com/neo4j/neo4j-go-driver/neo4j" //Go 1.8
)
func main() {
s, err := runQuery("bolt://<HOST>:<BOLTPORT>", "<USERNAME>", "<PASSWORD>")
if err != nil {
panic(err)
}
fmt.Println(s)
}
func runQuery(uri, username, password string) ([]string, error) {
configForNeo4j4 := func(conf *neo4j.Config) { conf.Encrypted = false }
driver, err := neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, ""), configForNeo4j4)
if err != nil {
return nil, err
}
defer driver.Close()
sessionConfig := neo4j.SessionConfig{AccessMode: neo4j.AccessModeRead, DatabaseName: "neo4j"}
session, err := driver.NewSession(sessionConfig)
if err != nil {
return nil, err
}
defer session.Close()
results, err := session.ReadTransaction(func(transaction neo4j.Transaction) (interface{}, error) {
result, err := transaction.Run(
`
MATCH (p:Product)-[:PART_OF]->(:Category)-[:PARENT*0..]->
(:Category {categoryName:$category})
RETURN p.productName as product
`, map[string]interface{}{
"category": "Dairy Products",
})
if err != nil {
return nil, err
}
var arr []string
for result.Next() {
value, found := result.Record().Get("product")
if found {
arr = append(arr, value.(string))
}
}
if err = result.Err(); err != nil {
return nil, err
}
return arr, nil
})
if err != nil {
return nil, err
}
return results.([]string), err
}
// install dotnet core on your system
// dotnet new console -o .
// dotnet add package Neo4j.Driver
// paste in this code into Program.cs
// dotnet run
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Neo4j.Driver;
namespace dotnet {
class Example {
static async Task Main() {
var driver = GraphDatabase.Driver("bolt://<HOST>:<BOLTPORT>",
AuthTokens.Basic("<USERNAME>", "<PASSWORD>"));
var cypherQuery =
@"
MATCH (p:Product)-[:PART_OF]->(:Category)-[:PARENT*0..]->
(:Category {categoryName:$category})
RETURN p.productName as product
";
var session = driver.AsyncSession(o => o.WithDatabase("neo4j"));
var result = await session.ReadTransactionAsync(async tx => {
var r = await tx.RunAsync(cypherQuery,
new { category="Dairy Products"});
return await r.ToListAsync();
});
await session?.CloseAsync();
foreach (var row in result)
Console.WriteLine(row["product"].As<string>());
}
}
}
// Add your the driver dependency to your pom.xml build.gradle etc.
// Java Driver Dependency: http://search.maven.org/#artifactdetails|org.neo4j.driver|neo4j-java-driver|4.0.1|jar
// Reactive Streams http://search.maven.org/#artifactdetails|org.reactivestreams|reactive-streams|1.0.3|jar
// download jars into current directory
// java -cp "*" Example.java
import org.neo4j.driver.*;
import static org.neo4j.driver.Values.parameters;
public class Example {
public static void main(String...args) {
Driver driver = GraphDatabase.driver("bolt://<HOST>:<BOLTPORT>",
AuthTokens.basic("<USERNAME>","<PASSWORD>"));
try (Session session = driver.session(SessionConfig.forDatabase("neo4j"))) {
String cypherQuery =
"MATCH (p:Product)-[:PART_OF]->(:Category)-[:PARENT*0..]->" +
"(:Category {categoryName:$category})" +
"RETURN p.productName as product";
var result = session.readTransaction(
tx -> tx.run(cypherQuery,
parameters("category","Dairy Products"))
.list());
for (Record record : result) {
System.out.println(record.get("product").asString());
}
}
driver.close();
}
}
Neo4j supports GraphQL and drivers for Node.js, Python, Go, Java, and .Net. Thanks to our community, we also have drivers for PHP, Ruby, R. Erlang, and Clojure.
Connect to a Neo4j database running anywhere, on-premises, self-hosted, or in the cloud as a fully-managed service with Neo4j AuraDB™
Explore Your Database and Craft the Perfect Cypher Query.
Whether you’re a beginner or an experienced Neo4j user, Browser is a developer-focused tool that's the ultimate place to write Cypher queries and explore the contents of your Neo4j graph database. Neo4j Browser comes out-of-the-box with all of Neo4j’s graph database offerings, including Neo4j Server (Community and Enterprise editions) and Neo4j Desktop (all OS versions).
For beginners, built-in guides help you learn the fundamentals of Neo4j and take your first steps to writing Cypher.
For beginners and experts alike, powerful code-completion assists you with writing queries so you can focus on the task at hand.
Give you results in graph and tabular representations according to your needs. A familiar “read-evaluate-print” construct helps you refine queries and be your most productive.
Quickly load your data into Neo4j.
Neo4j Data Importer simplifies importing data into a Neo4j graph database. Just import your flat file data, sketch out the nodes and relationships to represent your data in a graph data model, and begin loading. Learn more about Data Importer and get started now on Neo4j AuraDB Free.