我有 JSON 数据,我可以使用 https://github.com/thingdom/node-neo4j 创建 Node 和 Node 之间的关系。连接器。
我有以下 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 :
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 数据库(使用 Neo4j 数据库 UI): 现在的问题是当我查询 MATCH (n:nodes_type2) 返回 COUNT(n) 时。由于 json 中有 1000 个对象,它应该创建 1000 个 Node 。但结果会超过 1000 个(大约 9000 个),并且每次清除数据并重新启动脚本时都会不断变化。当我在结果中看到有多个 Node 具有相同的 UID 时。不应合并查询handel Node 匹配和增量计数器。合并会递增计数器,但在达到某个数字后,会使用相同的 UID 创建新 Node 。
最佳答案
根据您给定的查询,我假设生成的 UUID 在每个循环中看起来都不同:
1000 个循环,3 个查询,具有 3 个不同的 Node 标签。
您可以计算从数据库中获得的不同 uuid 数吗,例如:
MATCH (n) RETURN count(DISTINCT n.id)
关于javascript - 创建neo4j和nodejs的重复 Node ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26735267/