Skip to main content
Version: 1.2.x

SurrealDB for Neo4j developers

Neo4j to SurrealDB mapping

Quickly learn how to map your Neo4j knowledge to corresponding SurrealDB concepts and syntax.

Introduction

As a multi-model database, SurrealDB offers a lot of flexibility. Our SQL-like query language SurrealQL is a good example of this, where we often have more than one way to achieve the same result, depending on developer preference. In this mapping guide, we will focus on the syntax that most closely resembles the Cypher query language.

Concepts mapping

For more in-depth explanations of SurrealDB concepts, see the concepts page.

Neo4jSurrealDB
databasedatabase
node labeltable
noderecord
node propertyfield
indexindex
idrecord id
transactiontransaction
relationshipsrecord links, embedding and graph relations

Syntax mapping

Let's get you up to speed with SurrealQL syntax with some CRUD examples.

Create

As Neo4j is schemafull, only the SurrealQL schemafull approach is shown below. For a schemafull option see the define table page.

For more SurrealQL examples, see the create, insert and relate pages.

CypherSurrealQL
CREATE (John:Person {name:'John'}), (Jane:Person {name: 'Jane'})INSERT INTO person [ {id: "John", name: "John"}, {id: "Jane", name: "Jane"} ] Table implicitly created if it doesn't exist
MATCH (p:Person {name:'Jane'}), (pr:Product {name:'iPhone'}) CREATE (p)-[:ORDER]->(pr)RELATE person:Jane -> order -> product:iPhone There are many differences between how SurrealDB and Neo4j do graph relations. Check out the relate docs for more.
CREATE INDEX personNameIndex FOR (p:Person) ON (p.name)DEFINE INDEX idx_name ON TABLE person COLUMNS name

Read

For more SurrealQL examples, see the select, live select and return pages.

CypherSurrealQL
MATCH (p:Person) RETURN pSELECT * FROM person
MATCH (p:Person) RETURN p.nameSELECT name FROM person
MATCH (p:Person) WHERE p.name = "Jane" RETURN p.nameSELECT name FROM person WHERE name = "Jane"
EXPLAIN MATCH (p:Person) WHERE p.name = "Jane" RETURN p.nameSELECT name FROM person WHERE name = "Jane" EXPLAIN
MATCH (p:Person) RETURN count(*) as person_countSELECT count() AS person_count FROM person GROUP ALL
MATCH (p:Person) RETURN distinct p.nameSELECT array::distinct(name) FROM person GROUP ALL
MATCH (p:Person) RETURN p LIMIT 10SELECT * FROM person LIMIT 10
MATCH (p:Person)-[:ORDER]->(pr:Product) RETURN p.name, pr.nameSELECT name, ->order->product.name FROM person

Update

For more SurrealQL examples, see the update page.

CypherSurrealQL
MATCH (p:Person) WHERE p.name = "Jane" SET p.last_name = 'Doe' RETURN pUPDATE person SET last_name = "Doe" WHERE name = "Jane"
MATCH (p:Person) WHERE p.name = "Jane" REMOVE p.last_name RETURN pUPDATE person UNSET last_name WHERE name = "Jane"
MATCH (p:Person) WHERE p.name = "Jane" RETURN p.nameSELECT name FROM person WHERE name = "Jane"

Delete

For more SurrealQL examples, see the delete and remove pages.

CypherSurrealQL
MATCH (p:Person) WHERE p.name = "Jane" DELETE pDELETE person WHERE name = "Jane"
MATCH (p:Person) DELETE pDELETE person Node/Table still exists here but is empty
MATCH (p:Person) DELETE pREMOVE TABLE person Node/Table no longer exists