Possible to replace or overwrite a list entirely?

Is it possible to replace or overwrite a list entirely? I’m hoping to avoid having to do the query-then-diff-then-delete-and-set dance when changing lists entirely.

yeah, if you say <uid> <predicate> * will delete all the values for a predicate. Seems like this is what you want. Then, you can perform a mutation to update the values. This at least requires two round trips.

Yeah, that seems to be the only way.

I’m using JSON queries and am combining the delete and set in a mutation list. It seems to work, but I’m not sure it’s guaranteed to always work (that is, guaranteed to run the first mutation before the second mutation). The code is roughly:

const mu1 = new dgraph.Mutation();
mu1.setDeleteJson({list: null, uid: '0x123'});

const mu2 = new dgraph.Mutation();
mu2.setSetJson({list: ['0xdead', '0xbeef'], listOrder: '0xdead,0xbeef', uid: '0x123'});

const req = new dgraph.Request();
req.setMutationsList([mu1, mu2]);

const txn = client.newTxn();
await txn.doRequest(req);
await txn.commit();

(“listOrder” is my hack to allow me to set a fixed order of the list items in UI, only tangentially related to the original question)

yeah, it’s not guaranteed. Future version of Dgraph could do things different.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.