Tips and Tricks
We’re overhauling Dgraph’s docs to make them clearer and more approachable. If you notice any issues during this transition or have suggestions, please let us know.
Get sample data
Use the has
function to get some sample nodes.
Count number of connecting nodes
Use expand(_all_)
to expand the nodes’ edges, then assign them to a variable.
The variable can now be used to iterate over the unique neighboring nodes. Then
use count(uid)
to count the number of nodes in a block.
Search on non-indexed predicates
Use the has
function among the value variables to search on non-indexed
predicates.
Sort edge by nested node values
Dgraph sorting is based on a single level of the subgraph. To sort a level by the values of a deeper level, use query variables to bring nested values up to the level of the edge to be sorted.
Example: get all actors from a Steven Spielberg movie sorted alphabetically. The
actor’s name isn’t accessed from a single traversal from the starring
edge.
The name is accessible via performance.actor
.
Obtain unique results by using variables
To obtain unique results, assign the node’s edge to a variable. The variable can now be used to iterate over the unique nodes.
Example: get all unique genres from all of the movies directed by Steven Spielberg.
Usage of checkpwd
boolean
Store the result of checkpwd
in a query variable and then match it against 1
(checkpwd
is true
) or 0
(checkpwd
is false
).
Was this page helpful?