-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Experience Report
What you wanted to do
Create a simple way of "versioning nodes" using Upsert Block.
It is something that is very popular in the community.
One important thing to note is that Upsert is not fundamentally created for this (creating new nodes). It is designed to update existing nodes. That is, this would be another feature, which might have another name.
What you actually did
Set my original node (that will keep on the DB)
{
"set": [
{
"dgraph.type": "testNode",
"title": "Just a test",
"version": 1
}
]
}type testNode {
title
version
}upsert {
query {
q(func: type(testNode)){
T as title
Ver as version
VerIncr as math(Ver + 1)
}
}
mutation {
set {
_:newNode <title> val(T) .
_:newNode <version> val(VerIncr) .
_:newNode <dgraph.type> "testNode" .
}
}
}I also tried
upsert {
query {
q(func: type(testNode), first:1){
T as title
Ver as version
VerIncr as math(Ver + 1)
}
me(){
sT as sum(val(T))
sVerIncr as sum(val(VerIncr))
}
}
mutation {
set {
_:newNode <title> val(sT) .
_:newNode <version> val(sVerIncr) .
_:newNode <dgraph.type> "testNode" .
}
}
}If you run the query below, you gonna see that it creates new nodes indeed, but with no data. Which could be related to #4692 (feels like)
{
q(func: type(testNode)){
uid
title
version
dgraph.type
count(uid)
count2: count(uid) @filter(has(title))
}
}This is a potential duplicated of #4692, but as it has another intention. It feels like a new feature. This could even be used for data migrations. Data treatments from other databases that export in different structures that Dgraph supports.