This mapping guide focuses on the syntax that most closely resembles the Cypher query language.
To automatically migrate Neo4J data to SurrealDB, see the Neo4J page for the Surreal Sync tool.
| Neo4j | SurrealDB | ||
|---|---|---|---|
database | database | ||
node label | table | ||
node | record | ||
node property | field | ||
index | index | ||
id | record id | ||
transactions | transactions | ||
relationships | record links, embedding and graph relations |
The following shows some CRUD examples using SurrealQL syntax.
As Neo4j is schemaless, only the SurrealQL schemaless approach is shown below. For a schemafull option see the DEFINE TABLE page.
For more SurrealQL examples, see the CREATE, INSERT and RELATE pages.
Simple create/insert operations:
// Cypher CREATE (John:Person {name:‘John’}), (Jane:Person {name: ‘Jane’}) // SurrealQL // Table implicitly created if it doesn't exist INSERT INTO person [ {id: “John”, name: “John”}, {id: “Jane”, name: “Jane”} ]
Graph relations via the RELATE statement:
// Cypher MATCH (p:Person {name:‘Jane’}), (pr:Product {name:‘iPhone’}) CREATE (p)-[:ORDER]->(pr) // SurrealQL RELATE person:Jane->order->product:iPhone
Defining an index:
// Cypher CREATE INDEX personNameIndex FOR (p:Person) ON (p.name) // SurrealQL DEFINE INDEX idx_name ON TABLE person COLUMNS name
For more SurrealQL examples, see the SELECT, LIVE SELECT and RETURN pages.
Returning all the fields of a table:
// Cypher MATCH (p:Person) RETURN p // SurrealQL SELECT * FROM person
Returning a single field of a table:
// Cypher MATCH (p:Person) RETURN p.name // SurrealQL SELECT name FROM person
Using the WHERE clause to return certain records:
// Cypher MATCH (p:Person) WHERE p.name = “Jane” RETURN p.name // SurrealQL SELECT name FROM person WHERE name = “Jane”
Using EXPLAIN to detail the query plan used:
// Cypher EXPLAIN MATCH (p:Person) WHERE p.name = "Jane" RETURN p.name // SurrealQL SELECT name FROM person WHERE name = "Jane" EXPLAIN
Grouping and counting the number of records returned:
// Cypher MATCH (p:Person) RETURN count(*) as person_count // SurrealQL SELECT count() AS person_count FROM person GROUP ALL
See all distinct values for a field among the records of a table:
// Cypher MATCH (p:Person) RETURN distinct p.name // SurrealQL SELECT array::distinct(name) FROM person GROUP ALL
Returning up to a certain number of records:
// Cypher MATCH (p:Person) RETURN p LIMIT 10 // SurrealQL SELECT * FROM person LIMIT 10
See which person records have ordered a product via the order graph edge:
// Cypher MATCH (p:Person)-[:ORDER]->(pr:Product) RETURN p.name, pr.name // SurrealQL SELECT name, ->order->product.name FROM person
For more SurrealQL examples, see the UPDATE page.
Conditionally updating records that have a certain value for a field:
// Cypher MATCH (p:Person) WHERE p.name = "Jane" SET p.last_name = 'Doe' RETURN p // SurrealQL UPDATE person SET last_name = "Doe" WHERE name = "Jane"
Unsetting (removing) the value of a field for certain records:
// Cypher MATCH (p:Person) WHERE p.name = "Jane" REMOVE p.last_name RETURN p // SurrealQL UPDATE person UNSET last_name WHERE name = "Jane"
For more SurrealQL examples, see the DELETE and REMOVE pages.
Conditionally deleting records based on the value of a field:
// Cypher MATCH (p:Person) WHERE p.name = "Jane" DELETE p // SurrealQL DELETE person WHERE name = "Jane"
Deleting all records for a table (SurrealQL: table still exists):
// Cypher MATCH (p:Person) DELETE p // SurrealQL DELETE person
Deleting all records and table definition for a table:
// Cypher MATCH (p:Person) DELETE p // SurrealQL REMOVE TABLE person
RELATE statement documentation