junghc
(hc)
1
I have a Task type defined as follows:
type Task {
id: ID!
title: String!@id @search(by: [exact])
completed: Boolean!
gmtCreate:DateTime! @search(by: [hour])
gmtModified:DateTime! @search(by: [hour])
xid:String! @search(by: [hash])
}
I use Live Loader to import JSON data as follows:
[
{
"Task.title":"111",
"Task.completed": true,
"Task.gmtCreate": "2022-04-25T11:11:12Z",
"Task.gmtModified": "2022-05-09T11:25:12Z",
"Task.xid":"111"
},
{
"Task.title":"222",
"Task.completed": true,
"Task.gmtCreate": "2022-04-25T11:11:12Z",
"Task.gmtModified": "2022-05-09T11:25:12Z",
"Task.xid":"222"
}
]
Data export successfully.
Now, I want to use xid for data update, the JSON is as follows:
[
{
"Task.title":"111-1",
"Task.xid":"111"
}
]
I want to update Task.title with xid 111 to 111-1.
After executing the live command, the data is not updated.
When I do the same the way I use RDF, the data can be updated normally.
I don’t know what is wrong when using JSON file, please help me to point it out, thanks a lot.
pshaddel
(Poorshad Shaddel)
2
As far as I am concerned you can do this kind of update using uid. If you need to find something first then use upsert block:
upsert {
query {
q(func: eq(Task.title, "111-1")) {
v as uid
}
}
mutation {
set {
uid(v) <Task.xid> "111" .
}
}
}
junghc
(hc)
3
I have thought of the way you proposed, but I still want to know why the xid in Live Loader cannot take effect for JSON data.
mattph1
(Matt)
4
Can you provide the live loader command that you’re using? Are you specifying the upsertPredicate flag?
junghc
(hc)
5
Hi @mattph1
Thanks for your reply, the command is as follows:
/usr/local/bin/dgraph live --files test.json --upsertPredicate "Task.xid"
The content of test.json is:
[
{
"Task.title":"111-1",
"Task.xid":"111"
}
]
junghc
(hc)
6
@pshaddel
If I have the following type definition:
type Task {
id: ID!
title: String!
completed: Boolean!
userid: String!
user: User!
}
type User {
userid String! @id
username String! @id
name: String
tasks: [Task] @hasInverse(field: user)
}
Step 1: Import data into Task type
Step 2: Import data into User type
Now, I want to relate the data in Task and User.
I have a problem with the execution of the following statement, I have not thought of a solution, how should I do it?
upsert {
query {
q(func: type(Task)) {
b as Task.userid
}
q2(func:eq(User.userid, val(b))) {
n as uid
}
}
mutation {
set {
uid(u1) <Task.user> uid(n) .
}
}
}