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.
Set block
In DQL, you add data using a set mutation, identified by theset
keyword.
Delete block
A delete mutation, identified by thedelete
keyword, removes triples
from the store.
For example, if the store contained the following:
Wildcard delete
In many cases you need to delete multiple types of data for a predicate. For a particular nodeN
, all data for predicate P
(and all corresponding indexing)
is removed with the pattern S P *
.
S * *
deletes all the known edges out of a node, any reverse edges
corresponding to the removed edges, and any indexing for the removed data.
For mutations that fit the
S * *
pattern, only predicates that are among the
types associated with a given node (using dgraph.type
) are deleted. Any
predicates that don’t match one of the node’s types remains after an S * *
delete mutation.S
in the delete pattern S * *
has only a few predicates with a
type defined by dgraph.type
, then only those triples with typed predicates are
deleted. A node that contains un-typed predicates still exists after a S * *
delete mutation.
The patterns
* P O
and * * O
aren’t supported because it’s inefficient to
store and find all the incoming edges.Deletion of non-list predicates
Deleting the value of a non-list predicate (i.e a 1-to-1 relationship) can be done in two ways.- Using the wildcard delete (star notation) mentioned in the last section.
- Setting the object to a specific value. If the value passed isn’t the current value, the mutation succeeds but has no effect. If the value passed is the current value, the mutation succeeds and deletes the non-list predicate.
name
field that’s tagged with the language
tag es
is deleted. Other tagged values are left untouched.
Upsert block
Upsert is an operation where:- A node is searched for, and then
- Depending on if it’s found or not, either:
- Updating some of its attributes, or
- Creating a new node with those attributes.
Conditional upsert
The upsert block also allows specifying conditional mutation blocks using an@if
directive. The mutation is executed only when the specified condition is
true. If the condition is false, the mutation is silently ignored. The general
structure of Conditional Upsert looks like as follows:
@if
directive accepts a condition on variables defined in the query block
and can be connected using AND
, OR
and NOT
.
Example of conditional Upsert
Let’s say in our previous example, we know thecompany1
has less than 100
employees. For safety, we want the mutation to execute only when the variable
v
stores less than 100 but greater than 50 UIDs in it. This can be achieved as
follows:
json
dataset as follows: