Update: Using JSON to mutate on Dgraph. (cURL, Raw HTTP)

Doing a List With JSON via cURL and interact with it

Ref: Modifying predicate lists - #2 by MichelDiz

Schema:

testList: [string] .

Let’s create our List:

curl -X POST localhost:8080/mutate -H 'X-Dgraph-MutationType: json' -H 'X-Dgraph-CommitNow: true' -d  $'
  {
    "set": [
    { "testList": 
    [ "Grape","Apple","Strawberry","Banana","watermelon"] }
    ]
  }' | jq

Resulting:

{
  "data": {
    "myList": [
      {
        "uid": "0xd",
        "testList": [
          "Grape",
          "Apple",
          "Strawberry",
          "Banana",
          "watermelon"
        ]
      }
    ]
  }
}

Let’s then remove our Apple from this list (Remember, It’s case sensitive):

curl -X POST localhost:8080/mutate -H 'X-Dgraph-MutationType: json' -H 'X-Dgraph-CommitNow: true' -d  $'
{
  "delete": [
  { "uid": "0xd",
    "testList": "Apple"}
]
  }' | jq

Result:

{
  "data": {
    "myList": [
      {
        "uid": "0xd",
        "testList": [
          "Grape",
          "Strawberry",
          "Banana",
          "watermelon"
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 8586,
      "processing_ns": 370722,
      "encoding_ns": 710978
    },
    "txn": {
      "start_ts": 59,
      "lin_read": {
        "ids": {
          "1": 29
        }
      }
    }
  }
}