Contents
Graph Tip
You can use SHORTEST_PATH between any two documents in your database, provided there are edges connecting them.
Graph Queries
Perform native graph traversals and pattern matching directly within SoliDB using simple SDBQL extensions.
Overview
SoliDB treats every document relation as a graph edge. No special setup is required—just use standard collections and documents to model nodes and edges.
Vertices
Regular documents in any collection. Examples: Users, Products, Locations.
Edges
Documents that connect two vertices via `_from` and `_to` fields.
Collection Types
SoliDB supports two types of collections for graph modeling:
- Document Standard collections used to store vertices (nodes). Contains your data objects.
- Edge Special collections used to store edges (relationships). These documents MUST contain `_from` and `_to` fields.
Creating Edge Collections
{
"name": "friendships",
"type": 2 // 2 for Edge Collection (default is 1 for Document)
}
Or use the "Create" button in the Collections dashboard and select "Edge Collection".
Edge Documents
Edge documents are normal JSON documents but require two system fields:
{
"_from": "users/alice",
"_to": "users/bob",
"type": "friend_request",
"created_at": 123456789
}
SDBQL Graph Queries
Use the `TRAVERSE` keyword to walk the graph.
TRAVERSE OUTBOUND | INBOUND | ANY
FROM start_vertex
VIA edge_collection
DEPTH 1..3
Parameters
Common Patterns
Find Friends of Friends
Social NetworkFOR user IN users
FILTER user._key == 'alice'
FOR friend IN OUTBOUND user
GRAPH 'friendships'
OPTIONS { bfs: true, uniqueVertices: 'global' }
RETURN friend.name
This query starts at Alice, follows outgoing edges in the `friendships` graph for depth 1, and returns names of found vertices.
Shortest Path
RoutingFOR p IN OUTBOUND SHORTEST_PATH
'cities/paris' TO 'cities/berlin'
GRAPH 'roads'
RETURN p.name
Finds the shortest sequence of vertices connecting Paris to Berlin using the logic defined in the `roads` graph.