Graph and Cypher · Engineering
Shortest paths, pattern matching, and graph analytics
What NonoDB’s graph operations actually compute, how weights work, and where the bounded algorithms stop.
Once relationships live in the database, the next questions are usually: how are two things connected, what paths exist, and which nodes matter?
NonoDB supports shortest paths, all-shortest paths, linear pattern matching, and a set of bounded graph algorithms. They are useful for recommendation, dependency, fraud, and org-chart features without a second graph service.
Shortest path
{"op":"shortest_path", "coll":"nodes", "start":"alice", "target":"carol", "direction":"out", "max_depth":8, "weighted":false}With weighted:false, this is breadth-first search and weight is the hop count. With weighted:true, it is Dijkstra over the configured weight_field.
Missing, non-numeric, negative, or non-finite weights fail with invalid_query instead of being silently treated as zero. The result includes the full path, edge documents in via, weight, and hops.
all_shortest_paths returns every shortest path, not just one. limit_paths caps the number of paths; limit_nodes caps the explored set. Both operations accept edge_filter, node_filter, as_of, and projection.
Linear pattern matching
graph_match matches a linear sequence of variable-length relationship segments:
{"op":"graph_match", "coll":"nodes", "start":"alice", "pattern":[ {"direction":"out","labels":["KNOWS"],"min_hops":1,"max_hops":3}, {"direction":"out","labels":["WORKS_AT"],"min_hops":1,"max_hops":1} ], "limit":100}Each step has a direction, labels, min/max hops, edge filter, and node filter. The engine enforces relationship uniqueness within a path; a node can be revisited only through a different edge.
This is a JSON DSL, not Cypher. It does not support arbitrary subgraphs, WHERE expressions, or RETURN projections beyond node projection. For a richer read-only query surface, use the Cypher subset.
Algorithms
graph_algorithm supports:
- PageRank;
- degree centrality;
- weakly connected components;
- label propagation;
- k-core;
- degree distribution.
All six are read-only, use the same edge/node filters and labels as traversal, and are bounded by limit, max_nodes, max_edges, max_memory_bytes, and timeout_ms.
Exceeding a budget fails explicitly with invalid_query. Algorithms never return a silently truncated graph. The memory budget accounts for node ids, adjacency, and working maps, so it is enforced during computation, not only when serializing the result.
PageRank returns scores plus iterations and converged. Degree centrality returns in/out/total degree. Connected components returns component ids and sizes. Label propagation uses deterministic labels, with ties choosing the lexicographically smallest label. k-core uses deterministic peeling over both edge directions. Degree distribution returns an ascending histogram.
Why budgets matter
Graph algorithms are easy to write and easy to make accidentally quadratic. A small VM can disappear under a PageRank over a dense graph or a component scan with a huge working set.
NonoDB’s answer is to make the limits part of the API. A request that exceeds memory, nodes, edges, or time returns an error; it does not return an incomplete answer that looks complete. For long jobs, use the background job API described in the next post.
Paths are budgeted too
shortest_path and all_shortest_paths accept max_depth, limit_nodes, and limit_paths. A path that does not exist within those limits returns found: false or a truncated result, not an unbounded search. That makes the cost of a “how are these connected?” feature predictable on a small host.
What is missing
- No A* search.
- No arbitrary subgraph isomorphism.
- No full Cypher writes or graph projections.
- No distributed graph processing.
- No GDS parity beyond the documented procedures.
- No cross-database edges.
These are scope decisions. A graph feature inside a document database should not pretend to be a graph platform.
When it is useful
These operations fit:
- “how is this user connected to this account?”;
- dependency impact analysis;
- simple recommendation paths;
- org charts and permission inheritance;
- fraud rings that need paths, components, or centrality.
They do not fit heavy graph analytics over billions of edges. For that, use a graph engine designed for it.
The graph guide documents every operation, response shape, and budget; the graph analytics benchmark has reproducible timings.