# Inconsistent return result of query neo4j 3.5.2

**URL:** <https://community.neo4j.com/t/inconsistent-return-result-of-query-neo4j-3-5-2/4827>\
**Category:** Cypher\
**Created:** [February 4, 2019, 7:58am UTC](https://community.neo4j.com/t/inconsistent-return-result-of-query-neo4j-3-5-2/4827 "2019-02-04T07:58:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mail2michaelenn](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mail2michaelenn/32/2762_2.png) [@mail2michaelenn](https://community.neo4j.com/u/mail2michaelenn)\
**Post date:** [February 4, 2019, 7:58am UTC](https://community.neo4j.com/t/inconsistent-return-result-of-query-neo4j-3-5-2/4827/1 "2019-02-04T07:58:58Z")

</div>

I am using neo4j 3.5.2 Desktop with Nodejs. I am trying to update a user record properties and add/remove relationship with other nodes in same query:  
my query look like this:

```
                    MATCH (user:Dealer {email: $paramObj.email})
                    SET user += apoc.map.clean($paramObj, ["email","vehicles"],[])
                    WITH user, $paramObj.vehicles AS vehicles
                    UNWIND vehicles AS vehicle
                    MATCH(v:Vehicles {name:vehicle}) 
                    MERGE (user)-[r:SUPPLY_PARTS_FOR]->(v)
                    ON CREATE SET r.since = timestamp()
                    WITH vehicles,user
                    MATCH (user)-[r:SUPPLY_PARTS_FOR]->(v)
                    WHERE NOT apoc.coll.contains(vehicles,v.name)
                    DELETE r
                    WITH $paramObj.email AS dealeremail
                    MATCH (user:Dealer {email: dealeremail})
                    RETURN user

```

JS Code

```
 commons.session
         .run(queryDB, {paramObj: paramObj})                  
         .then(dealer => {
             console.log('DEALER DATA FROM dealer records..... ' + JSON.stringify(dealer.records));

```

The problem is 'user' at time is empty for the same query...same Dealer. Sometimes I also get :`{"code":"N/A","name":"Neo4jError"}` as the value of the catch error.

At first I thought since the last query ws a delete I have no 'user' so I added a `WITH` and return the `MATCH (user:Dealer....)`. That made no difference. I get 1 of 2 results ....the db is updated correctly but empty result return or code 'N/A' error.

**EDIT**

Ok...So I think I know what the problem is but not sure how to fix it....I was able to fix the code 'N/A' error I found a syntax error outside of the queryDB.

The issue of the returning empty 'user' array apparently is related to either not adding and/or deleting a vehicle where the result of that query would be zero rows.

How do I preserve the original 'user' result or save the email address to redo the query. I tried using WITH $paramObj.email AS dealerEmail but it seems that I cannot forward the dealerEmail...

Thought I could.

---

<div class="post-metadata">

**Author:** ![mail2michaelenn](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mail2michaelenn/32/2762_2.png) [@mail2michaelenn](https://community.neo4j.com/u/mail2michaelenn)\
**Post date:** [February 5, 2019, 5:19am UTC](https://community.neo4j.com/t/inconsistent-return-result-of-query-neo4j-3-5-2/4827/2 "2019-02-05T05:19:50Z")

</div>

I believe I found an answer.... This problem is as a result of returning zero rows so it dawned on me that the OPTIONAL MATCH would also return a NULL result but with a single row with null values. So I change the MATCH searching for a relationship to delete to an OPTIONAL MATCH.

```auto
  MATCH (user:Dealer {email: $paramObj.email})
  SET user += apoc.map.clean($paramObj, ["email","vehicles"],[])
                        WITH user, $paramObj.vehicles AS vehicles
                        UNWIND vehicles AS vehicle
                        MATCH(v:Vehicles {name:vehicle}) 
                        MERGE (user)-[r:SUPPLY_PARTS_FOR]->(v)
                        ON CREATE SET r.since = timestamp()
                        WITH vehicles,user
                        OPTIONAL MATCH (user)-[r:SUPPLY_PARTS_FOR]->(v)
                        WHERE NOT apoc.coll.contains(vehicles,v.name)
                        DELETE r
                        RETURN user    

```

This did the trick
