# Trying to delete from query result in dgraph-js

**URL:** <https://discuss.dgraph.io/t/trying-to-delete-from-query-result-in-dgraph-js/10563>\
**Category:** Dgraph\
**Tags:** kind:question\
**Created:** [September 23, 2020, 11:42pm UTC](https://discuss.dgraph.io/t/trying-to-delete-from-query-result-in-dgraph-js/10563 "2020-09-23T23:42:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bumpusfrancus](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/bumpusfrancus/32/5264_2.png) [@bumpusfrancus](https://discuss.dgraph.io/u/bumpusfrancus)\
**Post date:** [September 23, 2020, 11:42pm UTC](https://discuss.dgraph.io/t/trying-to-delete-from-query-result-in-dgraph-js/10563/1 "2020-09-23T23:42:23Z")

</div>

Hello,  
I’m trying to destroy all nodes that match a query’s results.

This is what currently isn’t working.

```auto
    // Get all sessions with a given session id.
    const query = `
      query getSession($sid: string) {
        session as var(func: eq(sessionId, $sid)) {
          uid
        }
      }
    `
    // Delete all of those sessions.
    const mutation = new Mutation();
    mutation.setDelNquads("uid(session) * * .");
    const request = new Request();
    request.setQuery(query);
    request.addMutations(mutation);
    request.setCommitNow(true);

```

I’m sure I’m missing something simple, but I’ve not had any luck figuring it out.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [September 24, 2020, 2:38am UTC](https://discuss.dgraph.io/t/trying-to-delete-from-query-result-in-dgraph-js/10563/2 "2020-09-24T02:38:09Z")

</div>

As far I can tell, DQL Variables aren’t supported on Upsert Block. But feels like it is working on JS client. Need to test tho.

> <https://github.com/dgraph-io/dgraph-js/blob/3f83745600818de64c968d9621a4cf7378bff147/tests/integration/delete.spec.ts#L54>

What is missing from your query is

```auto
const vars = {
        $id: "someID123",
    };
const varsMap = req.getVarsMap();
...

```

Continue here [dgraph-js/delete.spec.ts at 3f83745600818de64c968d9621a4cf7378bff147 · dgraph-io/dgraph-js · GitHub](https://github.com/dgraph-io/dgraph-js/blob/3f83745600818de64c968d9621a4cf7378bff147/tests/integration/delete.spec.ts#L16)

---

<div class="post-metadata">

**Author:** ![bumpusfrancus](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/bumpusfrancus/32/5264_2.png) [@bumpusfrancus](https://discuss.dgraph.io/u/bumpusfrancus)\
**Post date:** [September 24, 2020, 5:34pm UTC](https://discuss.dgraph.io/t/trying-to-delete-from-query-result-in-dgraph-js/10563/3 "2020-09-24T17:34:01Z")

</div>

Should I be using dql variables in this case? I’m concerned that if the behavior is unintentional, it may be patched out later. I trust the source of the value so putting the value directly into the template would work just as well for me.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [September 24, 2020, 6:14pm UTC](https://discuss.dgraph.io/t/trying-to-delete-from-query-result-in-dgraph-js/10563/4 "2020-09-24T18:14:24Z")

</div>

If it works for you, you can keep using DQL Vars. And now I know that it works on clients. Need to check if it works via RAW HTTP request. One thing I know is that DQL really doesn’t work on Ratel with custom value on the DQL Vars.

> [@bumpusfrancus](#):
>
> it may be patched out later.

Nope, we won’t do that.
