Skip to content

Commit c2edddc

Browse files
Adding docs about upsert (#66)
* Adding docs about upsert * Using correct function name
1 parent 0ae871e commit c2edddc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Mutation can be run using `txn.doRequest` as well.
187187

188188
```js
189189
const mu = new dgraph.Mutation();
190-
mu.setSetJson(q);
190+
mu.setSetJson(p);
191191

192192
const req = new dgraph.Request();
193193
req.setCommitNow(true);
@@ -244,7 +244,7 @@ Number of people named "Alice": 1
244244
Alice
245245
```
246246

247-
You can also use `txn.doQuery` function to run the query.
247+
You can also use `txn.doRequest` function to run the query.
248248
```js
249249
const req = new dgraph.Request();
250250
const vars = req.getVarsMap();
@@ -256,6 +256,13 @@ console.log(JSON.stringify(res.getJson()));
256256
```
257257

258258
### Running an Upsert: Query + Mutation
259+
260+
The `txn.doRequest` function allows you to run upserts consisting of one query and one mutation.
261+
Query variables could be defined and can then be used in the mutation. You can also use the
262+
`txn.doRequest` function to perform just a query or a mutation.
263+
264+
To know more about upsert, we highly recommend going through the docs at https://docs.dgraph.io/mutations/#upsert-block.
265+
259266
```js
260267
const query = `
261268
query {
@@ -271,7 +278,7 @@ req.setMutationsList([mu]);
271278
req.setCommitNow(true);
272279

273280
// Update email only if matching uid found.
274-
await dgraphClient.newTxn().doQuery(req);
281+
await dgraphClient.newTxn().doRequest(req);
275282
```
276283

277284
### Committing a transaction

0 commit comments

Comments
 (0)