Um, no. It should work. The following are my schema and initial dataset:
Schema:
<isread>: bool .
<raw>: string .
type <message> {
isread
raw
}
Initial Dataset:
{
set {
_:a <dgraph.type> "message" .
_:a <isread> "false" .
_:a <raw> "Hello there" .
}
}
Upsert that I made:
$ curl -H "Content-Type: application/rdf" -X POST localhost:8080/mutate?commitNow=true -d $'upsert {
query{
q(func: type(message)) @filter(eq(isread, false))
{
v as uid
}
}
mutation {
set {
uid(v) <isread> "true" .
}
}
}' | jq
Response:
{
"data": {
"code": "Success",
"message": "Done",
"queries": {
"q": [
{
"uid": "0x7"
}
]
},
"uids": {}
},
"extensions": {
"server_latency": {
"parsing_ns": 31365,
"processing_ns": 2097074,
"encoding_ns": 34441,
"assign_timestamp_ns": 834844,
"total_ns": 3248930
},
"txn": {
"start_ts": 4751,
"commit_ts": 4752,
"preds": [
"1-isread"
]
}
}
}
And when I query, I find that the values have been updated
q(func: type(message)){
expand(_all_)
}
Regarding the name “Upsert Block”
I see what the confusion is now. I sorta agree with you that it’s not a great name.
It’s called an “upsert block” because you use it to update/insert predicates (also nodes). In fact, inserting nodes is a special case, requiring the special format _:varname
for the subject. It’s basically a combination of query and mutation blocks.
Now, there’s no concept of “record” in Dgraph. See this blog post for more information of how data is stored in graphs in Dgraph.
We can of course have vague notions of "record"s. In a mutation
set {
_:foo <pred1> "pred1 value for foo" .
_:foo <pred2> "pred2 value for foo" .
_:bar <pred1> "pred1 value for bar" .
_:bar <pred2> "pred2 value for bar" .
}
We can mentally group foo
as a “record” and bar
as a “record”. But really they’re not real records in the same way as they are in a SQL database.
But we’re in a graph database regime, so we need to think of things in terms of graphs.