重复的节点创建了neo4j和nodejs
Duplicate Nodes created neo4j and nodejs
我有JSON数据,我用它创建节点和节点之间的关系https://github.com/thingdom/node-neo4j连接器。
我有以下JSON格式的
{
att0:"abcd",
att1:"val1",
att2:"val2",
att3:"val3",
att4:"val4",
att5:"val5",
att6:"val6",
att7:"val7",
att8:"val8"
} .... more like this around 1000
Here att0+att1 gives me unique id after md5 hash (let it be UID1) .
and att4 gives me unique id after md5 hash (let it be UID2).
and att7 gives me unique id after md5 hash (let it be UID3).
我正在创建以下属性的两个节点:
Node 1 :
{
id: UID1 ,
att3:"val3"
}
Node 2 :
{
id:UID2,
att5:"val5",
att6:"val6"
}
Relationship from Node 1 --> Node 2 :
{
id:UID3,
att5:"val8"
}
以下是我的数据插入查询:
for(i=0; i<1000; i++){ // 1000 objects in json
// create UID1,UID2 and UID3 based on above info for each object
// and create query string as mentioned below
query_string = MERGE (n:nodes_type1 {id:'UID1'})
ON CREATE SET n={ id:'UID1', att3:'val3'},n.count=1
ON MATCH SET n.count = n.count +1
MERGE (m:nodes_type2 {id:'UID2'})
ON CREATE SET m={ id:'UID2', att5:'val5', att6:'val6'},m.count=1
ON MATCH SET m.count = m.count +1
MERGE (n)-[x:relation_type {id:'UID3'} ]->(m)
ON CREATE SET x={ att8:'val8', id:'UID3' },x.count=1
ON MATCH SET x.count = x.count +1 return n
db.query(query_string, params, function (err, results) {
if (err) {
console.log(err);
throw err;
}
console.log("Node Created !!! "+ event_val)
});
}
首先,我使用以下外部查询(使用neo4j数据库UI)清除了我的neo4j数据库:现在的问题是当我查询MATCH(n:nodes_type2)返回COUNT(n)时。由于json中有1000个对象,因此应该创建1000个节点。但结果是超过1000(约9000),并且每次我清除数据并重新启动脚本时都会不断变化。当我在结果中看到有多个节点具有相同的UID时。不应该合并查询句柄节点匹配和增量计数器。Merge是递增计数器,但在某个数字之后,会创建具有相同UID的新节点。
根据您给定的查询,我假设每个循环中生成的UUID看起来不同:
1000个循环,3个具有3个不同节点标签的查询。
你能统计一下你从数据库中得到的不同的uuid吗,比如:
MATCH (n) RETURN count(DISTINCT n.id)
我保证您的查询是大规模并行执行的,
请确保为: nodes_type1(id)
和nodes_type2(id)
安装了唯一约束,否则MERGE无法保证唯一性。
您还应该更改查询以使用参数而不是文字值
它也应该是这样的:
MERGE (n:nodes_type1 {id:{id1}})
ON CREATE SET n.att3={att3},n.count=1
ON MATCH SET n.count = n.count +1
MERGE (m:nodes_type2 {id:{id2}})
ON CREATE SET m.att5={att5}, m.att6={att6},m.count=1
ON MATCH SET m.count = m.count +1
MERGE (n)-[x:relation_type {id:{id3}} ]->(m)
ON CREATE SET x.att8={att8},x.count=1
ON MATCH SET x.count = x.count+1
return n,r,m
我认为关系上的id和counter在实际用例中没有意义,但对于您的测试来说,
相关文章:
- nodejs-expressjs上传图像并显示它们
- TypeError:在不兼容的接收器nodejs上调用了方法Uint8Array.length
- NodeJS-readline暂停和恢复事件发射器(逐行读取)
- NodeJS日期格式不起作用
- Nested Q.all nodejs
- Nodejs API控制器,用于在API之间切换
- 否'访问控制允许来源'标头存在于IISNOde中请求的资源(AngularJS+NodeJs)上
- 如何在大型nodeJS代码的基础上逐步引入typescript
- 在Nodejs中Express输入DEBUG=app时权限被拒绝/bin
- 无法使用nodeJS在html中设置Image src
- 与域在同一台计算机上运行的NODEJS服务器的CORS错误
- NodeJS API调用中Array中的Push和Pull元素
- 基于api密钥的NodeJS web服务
- 在gump和nodejs中使用Typescript时,未定义对require和exports的引用
- “util.inherits”和在NodeJS中扩展原型之间的区别
- 将一个方法转换为promise:Nodejs
- nodejs中匿名函数的使用
- 使用 neo4j-nodejs API 在 neo4j 中创建关系
- 重复的节点创建了neo4j和nodejs
- NodeJS和Neo4j的异步行为问题