Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获得;参考错误“;使用cypher查询在用于neo4j导入的nodejs应用程序中执行多个承诺链接时出错_Javascript_Node.js_Neo4j_Cypher - Fatal编程技术网

Javascript 获得;参考错误“;使用cypher查询在用于neo4j导入的nodejs应用程序中执行多个承诺链接时出错

Javascript 获得;参考错误“;使用cypher查询在用于neo4j导入的nodejs应用程序中执行多个承诺链接时出错,javascript,node.js,neo4j,cypher,Javascript,Node.js,Neo4j,Cypher,我正在使用neo4j js驱动程序(和异步实用程序模块)编写nodejs应用程序,以使用要导入neo4j数据库的项目源js文件的数据 在我的测试项目文件夹“testapp”中有两个文件夹,即“State”和“City”,以及一个“country.js”文件。 “country.js”文件包含国家的名称和id,countryid用作文件夹“State”和“City”中js文件的参数 --country.js文件中的代码片段 const countries= [ { id: "1", label:

我正在使用neo4j js驱动程序(和异步实用程序模块)编写nodejs应用程序,以使用要导入neo4j数据库的项目源js文件的数据

在我的测试项目文件夹“testapp”中有两个文件夹,即“State”和“City”,以及一个“country.js”文件。 “country.js”文件包含国家的名称和id,countryid用作文件夹“State”和“City”中js文件的参数

--country.js文件中的代码片段

const countries= [
{ id: "1", label: "USA" }, 
{ id: "2", label: "Scotland" }
];
module.exports = countries;
“State”文件夹中有js文件,其命名约定如下:(Country-1-statelist.jsCountry-2-statelist.js等等)

--“状态”文件夹中js文件的示例

类似地,“城市”文件夹也有js文件,其命名约定如下:(Country-1-state-1-list.jsCountry-1-state-2-list.js等等)

--“城市”文件夹中特定js文件的示例

因此,我尝试添加带有标签国家、州和城市的节点,以便在不改变其关系的情况下导入它们。但我在尝试使用多链承诺将其导入测试数据库时,在nodejs中遇到了错误

到目前为止,我能够从“State”文件夹导入country.js和其他js文件中的数据。但是,在尝试从“City”文件夹的js文件执行相同操作时,我得到了“ReferenceError:item未定义”错误

为此,我在nodejs中创建了index.js文件,其代码如下:

const neo4j=require('neo4j-driver')。v1;
常量驱动器=neo4j.驱动器(“bolt://localhost,neo4j.auth.basic(“neo4j”,“testapp”);
const session=driver.session();
const async=require('async');
const apppath='/Users/reactor/Documents/testapp';
const country=require(应用路径+“/国家”);
async.eachSeries(国家(项目,回调)=>{
const resPromise=session.run(
`创建(c:country{label:${item.label}),id:${item.id})返回c.id`
);
重新提议
。然后((数据)=>{
返回insertState(item.id);
}
)
.那么
(
(完成)=>{
回调(空);
}
)
.接住
(
(错误)=>{
回调(err);
}
);
},
(错误)=>{
控制台日志(err);
session.close();
driver.close();
}
);
函数insertState(countryID){
让state=require(apppath+'/state/Country-'+countryID+'-statelist.js');
返回新承诺((解决、拒绝)=>{
async.eachSeries(state.items,(item1,item2,回调)=>{
const resPromise=session.run(
`
创建(s:state{label:${item.label}),id:${item.id})
用s
比赛(c:国家队)
其中c.id='${countryID}'
创建(s)-[r:位于]->(c)
返回c,s
`
);
重新提议
。然后((状态)=>{
console.log(状态);
回调(空);
})
重新提议
。然后((数据)=>{
返回insertCity(item1.id,item2.id);
})
。然后((完成)=>{
回调(空);
}
)
.catch((错误)=>{
回调(err);
});
},(错误)=>{
如果(错误){
拒绝(错误);
}
决心(正确);
});
}
);
}
//当我插入下面的代码块时,问题出现了!!
函数insertCity(countryID、stateID){
let city=require(apppath+'/city/Country-'+countryID+'-state-'+stateID+'-list.js');
返回新承诺((解决、拒绝)=>
{
async.eachSeries(city.items,()=>{
const resPromise=session.run(
`
创建(w:city{label:${item.label}),id:${item.id})
与w
匹配(s:状态)
其中s.id='${stateID}'
/*我该如何在这个cypher查询中使用countryid参数?因为它与这个查询中的标签“country”没有直接关系*/
创建(w)-[r:在]->(s)中显示
返回w
`
);
重新提议
.然后((城市)=>{
控制台.日志(城市);
回调(空);
})
。然后((完成)=>{
回调(空);
})
.catch((错误)=>{
回调(err);
});
},(错误)=>{
如果(错误){
拒绝(错误);
}
决心(正确);
});
}
);
}
insertState()
insertCity()
中,您试图取消对
项的引用。标签
项.id
,但范围中没有

    const data = {"params":{"country_id":"1"},"items":
    [{"id":"1","label":"Alaska"},{"id":"2","label":"Alabama"}]
      module.exports = data;    
const data = 
  {"params":
   {"country_id":"1","state_id":"1"},

   "items":[
       {"id":"1","label":"New York"},
       {"id":"2","label":"Chicago"}
   ]
        }
 module.exports = data;