Skip to content

Queries using parameters through the Javascript neo4j-driver does not work #4452

Description

@abkeysight

Hello,

We are facing an issue where a query that should work, doesn't when using parameters. When the values used in the parameters are manually put in the cypher string, the query is successful.

Reproduce

  1. Launch the Arcade DB v26.5.1 docker container with docker compose
version: "3"
services:
  db:
    image: arcadedata/arcadedb:26.5.1
    container_name: arcadedb
    ports:
      - "7687:7687"
      - "2480:2480"
      - "2424:2424"
    environment:
      JAVA_OPTS: >
        -Darcadedb.server.plugins=Bolt:com.arcadedb.bolt.BoltProtocolPlugin
        -Darcadedb.profile=low-ram
        -Darcadedb.server.rootPassword=playwithdata
        -Darcadedb.server.defaultDatabases=mydatabase[]
        -Darcadedb.bolt.defaultDatabase=mydatabase
        -Darcadedb.bolt.debug=true
      ARCADEDB_OPTS_MEMORY: >
        -Xms16M
        -Xmx512M
  1. Run the following queries through Arcade Studio on port 2480

Assuming _id: 34359738368 is returned for ag-001, _id: 51539607552 for tag1, and _id: 51539607553 for tag2

CREATE CONSTRAINT unique_idx IF NOT EXISTS FOR (n:Foo) REQUIRE n.id IS UNIQUE

CREATE (fooagent:FooAgent:Foo {id: 'ag-001', _id: null}) 
RETURN fooagent {.*, _id: ID(fooagent)} AS fooagent

CREATE (tag:Tag {name:"tag1", value: "val1", _id:null}) RETURN tag {.*, _id: ID(tag)} AS tag

CREATE (tag:Tag {name:"tag2", value: "val2", _id:null}) RETURN tag {.*, _id: ID(tag)} AS tag


MATCH (from) WHERE ID(from) = 34359738368 
MATCH (to) WHERE ID(to) = 51539607552
MERGE (from)-[:agentTags {refType: 'false'}]->(to) 
RETURN from {.*, agentTags: to {.*}} as from

MATCH (from) WHERE ID(from) = 34359738368 
MATCH (to) WHERE ID(to) = 51539607553
MERGE (from)-[:agentTags {refType: 'false'}]->(to) 
RETURN from {.*, agentTags: to {.*}} as from
  1. Run the following typescript file
import neo4j from 'neo4j-driver' //version 6.0.1


const driver = neo4j.driver(
    'bolt://localhost:7687',
    neo4j.auth.basic('root', 'playwithdata'),
    {disableLosslessIntegers: true}
)


let s1 = driver.session();
let t1 = s1.beginTransaction();

try{
    const res = await t1.run(`MATCH (parentNode)-[:agentTags*0..]->(x:Tag { name: $nameParam})
                         WHERE ID(parentNode) = $parentId AND NOT x:Foo
                         WITH x, x {.*, _id: ID(x)} AS prop
                         DETACH DELETE x
                         RETURN prop`, 
    {
        nameParam: 'tag2', parentId: 34359738368
    });
    await t1.commit();
    console.log("RESULT: ", res);
}catch (error){
    console.log("Error: ", error);
    await t1.rollback();
}

s1.close();
driver.close();

Expected Results:

Image
RESULT:  {
  records: [
    Record {
      keys: [Array],
      length: 1,
      _fields: [Array],
      _fieldLookup: [Object]
    }
  ],
  summary: ResultSummary {
    query: {
      text: "MATCH (parentNode)-[:agentTags*0..]->(x:Tag { name: 'tag2'})\n" +
        '                         WHERE ID(parentNode) = 34359738368 AND NOT x:Foo\n' +
        '                         WITH x, x {.*, _id: ID(x)} AS prop\n' +
        '                         DETACH DELETE x\n' +
        '                         RETURN prop',
      parameters: [Object]
    },
    queryType: 'w',
    counters: QueryStatistics { _stats: [Object], _systemUpdates: 0 },
    plan: false,
    profile: false,
    notifications: [],
    gqlStatusObjects: [ [GqlStatusObject] ],
    server: ServerInfo {
      address: 'localhost:7687',
      agent: 'Neo4j/5.26.0 compatible (ArcadeDB 26.5.1)',
      protocolVersion: [ProtocolVersion]
    },
    resultConsumedAfter: 4,
    resultAvailableAfter: 4,
    database: { name: null }
  }
}

Current Results:

Image
RESULT:  {
  records: [],
  summary: ResultSummary {
    query: {
      text: 'MATCH (parentNode)-[:agentTags*0..]->(x:Tag { name: $nameParam})\n' +
        '                         WHERE ID(parentNode) = $parentId AND NOT x:Foo\n' +
        '                         WITH x, x {.*, _id: ID(x)} AS prop\n' +
        '                         DETACH DELETE x\n' +
        '                         RETURN prop',
      parameters: [Object]
    },
    queryType: 'w',
    counters: QueryStatistics { _stats: [Object], _systemUpdates: 0 },
    plan: false,
    profile: false,
    notifications: [],
    gqlStatusObjects: [ [GqlStatusObject] ],
    server: ServerInfo {
      address: 'localhost:7687',
      agent: 'Neo4j/5.26.0 compatible (ArcadeDB 26.5.1)',
      protocolVersion: [ProtocolVersion]
    },
    resultConsumedAfter: 1,
    resultAvailableAfter: 0,
    database: { name: null }
  }
}

Expected results are achieved when $nameParam and $parentId are replaced in the query string with the values passed in the map object, i.e. the following produces the expected results

import neo4j from 'neo4j-driver'


const driver = neo4j.driver(
    'bolt://localhost:7687',
    neo4j.auth.basic('root', 'playwithdata'),
    {disableLosslessIntegers: true}
)


let s1 = driver.session();
let t1 = s1.beginTransaction();

try{
    const res = await t1.run(`MATCH (parentNode)-[:agentTags*0..]->(x:Tag { name: 'tag2'})
                         WHERE ID(parentNode) = 34359738368 AND NOT x:Foo
                         WITH x, x {.*, _id: ID(x)} AS prop
                         DETACH DELETE x
                         RETURN prop`, 
    {
        nameParam: 'tag2', parentId: 34359738368
    });
    await t1.commit();
    console.log("RESULT: ", res);
}catch (error){
    console.log("Error: ", error);
    await t1.rollback();
}

s1.close();
driver.close();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions