cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Executing multi-statement query via NodeJS driver

Is it possible to execute query with 2+ statements in a single transaction.run call?

 

  const query = `
    MERGE (:TestLabel {name: $name1});
    MERGE (:TestLabel {name: $name2});`;

  const queryParams = {
    name1: 'Test Name 1',
    name2: 'Test Name 2',
  };

  await transaction.run(query, queryParams);

 

 

Execution of the code above gives following error:

 

Expected exactly one statement per query but got: 2 (line 1, column 0 (offset: 5))        
"    MERGE (:TestLabel {name: $name1});"
     ^
Neo4jError: Expected exactly one statement per query but got: 2 (line 1, column 0 (offset: 5))
"    MERGE (:TestLabel {name: $name1});"
     ^

    at captureStacktrace (D:\Work\Internal\retail-platform-performance-test\node_modules\neo4j-driver-core\lib\result.js:239:17)
    at new Result (D:\Work\Internal\retail-platform-performance-test\node_modules\neo4j-driver-core\lib\result.js:59:23)  
    at newCompletedResult (D:\Work\Internal\retail-platform-performance-test\node_modules\neo4j-driver-core\lib\transaction.js:433:12)
    at Object.run (D:\Work\Internal\retail-platform-performance-test\node_modules\neo4j-driver-core\lib\transaction.js:287:20)
    at Transaction.run (D:\Work\Internal\retail-platform-performance-test\node_modules\neo4j-driver-core\lib\transaction.js:137:34)
    at D:\Work\Internal\retail-platform-performance-test\dist\seeds\static.js:46:23
    at Generator.next (<anonymous>)
    at D:\Work\Internal\retail-platform-performance-test\dist\seeds\static.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (D:\Work\Internal\retail-platform-performance-test\dist\seeds\static.js:4:12)
    at createNodes (D:\Work\Internal\retail-platform-performance-test\dist\seeds\static.js:20:72)
    at D:\Work\Internal\retail-platform-performance-test\dist\seeds\static.js:52:11
    at Generator.next (<anonymous>)
    at fulfilled (D:\Work\Internal\retail-platform-performance-test\dist\seeds\static.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

 

 

 

 

1 ACCEPTED SOLUTION

Try removing the semicolons after each merge. 

View solution in original post

2 REPLIES 2

Try removing the semicolons after each merge. 

That works - thanks a lot!