I ran some queries that created nodes without a type (by accident). I can find them because I happen to know what predicates I included with the node, but I’m concerned I may have made this mistake elsewhere, or may in the future. What is the best way to find typeless nodes?
The only option I have come up with so far is to query the schema (schema {}
) and then run a query for each predicate with a filter. Is this a good method or is there a better option?
const schema = await txn.queryWithVars('schema {}');
const predicates = schema.getJson().schema.map(s => s.predicate);
const query = `query {
${predicates.map(p => `${p}(func: has(${p})) @filter(not has(dgraph.type)) { uid }`).join('\n')}
}`;
const typeless = await txn.queryWithVars(query);
const json = typeless.getJson();
Object.keys(json).
filter(p => json[p].length > 0).
forEach(p => console.log(`${p}: ${json[p].map(n => n.uid)}`));