Skip to content

Commit

Permalink
docs: Add details for JSON file mutations with curl.
Browse files Browse the repository at this point in the history
A user asked for more clarification in the docs about this section to avoid
errors related to the format of their JSON file.
  • Loading branch information
danielmai committed Jul 3, 2019
1 parent 43c8d38 commit 727b246
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions wiki/content/mutations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,58 @@ Mutation with a JSON file:
curl -H "Content-Type: application/json" -X POST localhost:8080/mutate?commitNow=true -d @data.json
```

where the contents of data.json looks like the following:

```json
{
"set": [
{
"name": "Alice"
},
{
"name": "Bob"
}
]
}
```

The JSON file must follow the same format for mutations over HTTP: a single JSON
object with the `"set"` or `"delete"` key and an array of JSON objects for the
mutation. If you already have a file with an array of data, you can use `jq` to
transform your data to the proper format. For example, if your data.json file
looks like this:

```json
[
{
"name": "Alice"
},
{
"name": "Bob"
}
]
```

then you can transform your data to the proper format with the following `jq`
command, where the `.` in the `jq` string represents the contents of data.json:

```sh
cat data.json | jq '{set: .}'
```

```
{
"set": [
{
"name": "Alice"
},
{
"name": "Bob"
}
]
}
```

## Upsert Block

The Upsert block allows performing queries and mutations in a single request. The Upsert
Expand Down

0 comments on commit 727b246

Please sign in to comment.