diggy
(Dgraph Bot)
1
Moved from GitHub dgraph-js/34
Posted by lazharichir:
Hello - quick question!
mu.setDeleteJson([ { 'topic.external.wikidata': null, uid: '0x9c671a' } ]);
Returns:
2 UNKNOWN: Please use * with delete operation for non-list type: [_predicate_]
The predicate topic.external.wikidata
is a int
, non-list.
Anything I am missing? I want to delete the predicate topic.external.wikidata
for the uid
specified.
diggy
(Dgraph Bot)
2
gpahal commented :
It’s working with this example.
const dgraph = require("dgraph-js");
async function main() {
const clientStub = new dgraph.DgraphClientStub("localhost:9080");
const client = new dgraph.DgraphClient(clientStub);
console.log("DROP ALL");
let op = new dgraph.Operation();
op.setDropAll(true);
await client.alter(op);
console.log("SET SCHEMA");
const schema = `
name: string @index(term) .
topic.external.wikidata: int .
`;
op = new dgraph.Operation();
op.setSchema(schema);
await client.alter(op);
console.log("CREATE DATA");
let txn = client.newTxn();
let uid;
try {
const mu = new dgraph.Mutation();
mu.setSetNquads(`
<_:a> <name> "a" .
<_:a> <topic.external.wikidata> "1" .
<_:b> <name> "b" .
<_:b> <topic.external.wikidata> "2" .
`);
const assigned = await txn.mutate(mu);
await txn.commit();
uid = assigned.getUidsMap().get("b")
} finally {
await txn.discard();
}
console.log("QUERY DATA");
let query = `{
all(func: has(name)) {
uid
name
topic.external.wikidata
}
}`;
let res = await client.newTxn().query(query);
let ppl = res.getJson();
console.log(`BEFORE:\nNumber of people: ${ppl.all.length}`);
console.log(`People: ${JSON.stringify(ppl)}\n`);
console.log("DELETE DATA");
txn = client.newTxn();
try {
const mu = new dgraph.Mutation();
mu.setDeleteJson([{ uid: uid, "topic.external.wikidata": null }]);
await txn.mutate(mu);
await txn.commit();
} finally {
await txn.discard();
}
console.log("QUERY DATA");
query = `{
all(func: has(name)) {
uid
name
topic.external.wikidata
}
}`;
res = await client.newTxn().query(query);
ppl = res.getJson();
console.log(`AFTER:\nNumber of people: ${ppl.all.length}`);
console.log(`People: ${JSON.stringify(ppl)}`);
clientStub.close();
}
main().then(() => {
console.log("DONE!");
}).catch((e) => {
console.log("ERROR: ", e);
});
diggy
(Dgraph Bot)
3
gpahal commented :
Can you share a bit more of your code because the error seems to indicate predicate name _predicate_