0

I have the following function:

async function getCoordinates(someId) {
  var coordinates = {longitude: 0, latitude: 0};
  var result = await neo4jsession.writeTransaction(tx =>
    tx.run(`MATCH (p:SomeEntity)
    WHERE p.some_id = "${someId}"
    RETURN p.longitude, p.latitude LIMIT 1`)
  );
  coordinates.longitude = results.records[0].get("p.longitude");
  coordinates.latitude = results.records[0].get("p.latitude");
  return coordinates;
}

The problem is, in the above, when I print console.log(result), I see that the returned result doesn't have any Records. However, when I run the query:

MATCH (p:SomeEntity)
WHERE p.some_id = 12345
RETURN p.longitude, p.latitude LIMIT 1

for the same some_id I get the expected result. I have some other functions with queries that are working. I get this issue only with this query.

Since the query is not returning any records, coordinates.longitude = results.records[0].get("p.longitude"); is failing with a TypeError.

7
  • are you sure some_id is not "id of node" ? and print results instead of checking object properties Commented Jan 9, 2018 at 7:51
  • What do you mean? some_id is an attribute of a node. Commented Jan 9, 2018 at 7:53
  • to match id of node (auto generated id) we use id(node)=12345 like syntex Commented Jan 9, 2018 at 7:54
  • @shivshankar I checked this. some_id is not the internal id of the node. It's a custom attribute. So, this didn't work. Commented Jan 9, 2018 at 8:12
  • 1
    also make sure ${someId} is a numeric value may be you are comparing numeric to string. remove quote if some_id is numeric Commented Jan 9, 2018 at 8:17

1 Answer 1

1

there may two concern

are you sure some_id is not "id of node" ? to match id of node (auto generated id) we use id(node)=12345 syntax

make sure ${someId} is a numeric value may be you are comparing numeric to string. remove quote if some_id is numeric

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.