带有 Neo4j 的 Nodejs:多合并查询的语法错误

Nodejs with Neo4j: Sytax error on a multi - merge query

我有以下功能,可将一行数据插入基于行的条目(excell 或 csv 条目)到我的 neo4j 中:

  self.insertFromExcellRow=function(row){

      // _neo4j a neo4j connection from neo4j-driver
      const session = _neo4j.session();

      //The replacement of the values where it will get stored in neo4j
      const values={
        'dataid':row.dataId,
        'dataAsset':row.dataAsset,
        'dataSubject':row.dataSubject,
        'purpoce':row.purpoce,
        'source':row.source,
        'pIIclasification':row.pIIclasification,
        'securityClassification':row.securityClassification,
        'categoryInfo':row.categoryInfo,
        'appName':row.collectedBy,
        'securityControl':row.securityControl,
        'usedBy':row.usedBy,
        'whoCanAccess':row.access,
        'securityControl':row.securityControl,
        'dataTransferMechanism':row.dataTranserMechanism,
        'serviceName':row.collectedBy
      }

      let query=`MERGE (DATA_ASSET:DATA_ASSET {id:{dataid} ,name:{dataAsset}, subject:{dataSubject}, classification:{securityClassification})
      MERGE (SERVER_OR_SERVICE:SERVER_OR_SERVICE { name: {serviceName} })
      MERGE (APPLICATION:APPLICATION { name:{appName} })
      MERGE (DATA_CONSUMER:DATA_CONSUMER {usedBy: {usedBy}, accessOrgPositions: {whoCanAccess}})
      MERGE (SERVER_OR_SERVICE)<-[:FROM]-(DATA_CONSUMER)-[:ACCESSING]->(DATA_ASSET)
      MERGE (DATA_ASSET)-[:COLLECTED_BY]->(APPLICATION)
      `;

      if(row.processingType.toLowerCase()==='transmission') {
        query+=`MERGE (DATA_ASSET)-[:GETS]->(TRANSMITTED:TRANSMITTED { id:{dataid},purpoce:{purpoce},source:{source},pIIclasification:{pIIclasification},categoryInfo:{categoryInfo} })<-[:FROM]-(APPLICATION)
        MERGE (DATA_ASSET)-[:GETS]->(TRANSMITTED)-[:INTO { transferMechanism:{dataTransferMechanism}, securityControl:{securityControl}}]->(SERVER_OR_SERVICE)`;
      } else if(row.processingType.toLowerCase()==='storage') {
        query+=`MERGE (DATA_ASSET)-[:GETS]->(STORED:STORED { id:{dataid},purpoce:{purpoce},source:{source},pIIclasification:{pIIclasification},categoryInfo:{categoryInfo} })<-[:FROM]-(APPLICATION)
        MERGE (DATA_ASSET)-[:GETS]->(STORED)-[:INTO { transferMechanism:{dataTransferMechanism}, securityControl:{securityControl}}]->(SERVER_OR_SERVICE)`;
      }

      session.run(query,values).then((data)=>{
        console.log('Success');
        self.fetchDataAsTable();
      }).catch((error)=>{
        _emmiter.emit('insert_row_error',error);
        console.error(error);
      });
  }

但由于某种原因我得到了错误:

{ Neo4jError: Invalid input ')': expected whitespace, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or '}' (line 1, column 124 (offset: 123))
"MERGE (DATA_ASSET:DATA_ASSET {id:{dataid} ,name:{dataAsset}, subject:{dataSubject}, classification:{securityClassification})"
                                                                                                                             ^ 
at captureStacktrace (/opt/map/node_modules/neo4j-driver/lib/v1/result.js:200:15)
at new Result (/opt/map/node_modules/neo4j-driver/lib/v1/result.js:73:19)
at Session._run (/opt/map/node_modules/neo4j-driver/lib/v1/session.js:122:14)
at Session.run (/opt/map/node_modules/neo4j-driver/lib/v1/session.js:101:19)
at self.insertFromExcellRow (/opt/map/src/services/graph.js:67:15)
at /opt/map/src/services/excell.js:118:7
at process._tickCallback (internal/process/next_tick.js:150:11)
code: 'Neo.ClientError.Statement.SyntaxError',
name: 'Neo4jError' }

请问各位大佬知道这是为什么吗?

看来您需要插入一个结束符 }

MERGE (DATA_ASSET:DATA_ASSET {id:{dataid} ,name:{dataAsset}, subject:{dataSubject}, classification:{securityClassification} here )

它关闭 'DATA_ASSET:DATA_ASSET' { .. }

如果错误消息说:"You need a closing curly brace"而不是把字典扔给你,那就更好了——最后一个选项就是你需要的,哈哈..

至少,它确实有一个很好的'^'字符来告诉你错误在哪里。