As you currently have it, only the last setSetNquads call is ultimately applied.
So a piece of data has to be requested hundreds of times, which is very slow
like this:
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
String field = obj.getString(fieldName);
String query1 = “”
String query2 = '"
DgraphJavaClient.upsert(dgraphClient,query2,“uid(u) <”+fieldName+"> “”+field+"" .");
DgraphJavaClient.upsert(dgraphClient,query2,“uid(u) “”+formatDt+”" .");
DgraphJavaClient.upsert(dgraphClient,query1,“uid(v) uid(u) (update=”+formatDt+") .");
}
Yes, the setSetNquads will overwrite the existing value, not append to the existing value. However, there can be more than one nquad in the SetNquads field. So your code can append the nquads first and then call setSetNquads once. Keep in mind that you don’t want to send too many nquads in a single mutation because you increase the chances of the transaction being aborted due to conflicts.
So the flow should be like this.
Batch the nquads you want to set. For this example, let’s say the batch size is 10.
After you have enough nquads for a batch, create a new transaction, call setSetNquads and then call mutate or upsert.
Commit your transaction. You might have to retry if there was a conflict and the transaction had to be aborted.
Empty the batch and repeat the process until all your nquads have been sent to the cluster.