gpt4 book ai didi

node.js - 在单个密码查询nodejs中创建多个不同 Node 之间的关系

转载 作者:太空宇宙 更新时间:2023-11-04 00:23:22 25 4
gpt4 key购买 nike

var arr = [{id:"1",created_at:"1",role:"EMPLOYEE"},{id:"2",created_at:"2",role:"EMPLOYEE"},{id:"3",created_at:"3",role:"VISITOR"},{id:"4",created_at:"4",role:"EMPLOYEE"},{id:"5",created_at:"5",role:"FRIEND"},{id:"6",created_at:"6",role:"EMPLOYEE"},{id:"7",created_at:"7",role:"CO_WORKER"},{id:"8",created_at:"8",role:"EMPLOYEE"},{id:"9",created_at:"9",role:"EMPLOYEE"},{id:"10",created_at:"10",role:"STUDENT"}];

var query = 'MATCH (page:pages {id:"435345435"}) ';
for (var i = 0; i < arr.length; i++) {
query += 'MATCH (user'+i+':users {id:"'+ arr[i].id +'"}) user'+i+' CREATE (user'+i+')-[r'+i+':MEMBER_OF {rId:"'+uuid()+'",relation:"'+ arr[i].role +'",createdAt:"'+ arr[i].created_at +'"} ]->(page) ';
}
query += 'RETURN r0';

这给了我 -

MATCH (page:pages {id:"435345435"}) MATCH (user0:users {id:"1"}) CREATE (user0)-[r0:MEMBER_OF {rId:"0",relation:"EMPLOYEE",createdAt:"1"} ]->(page) MATCH (user1:users {id:"2"}) CREATE (user1)-[r1:MEMBER_OF {rId:"1",relation:"EMPLOYEE",createdAt:"2"} ]->(page) MATCH (user2:users {id:"3"}) CREATE (user2)-[r2:MEMBER_OF {rId:"2",relation:"VISITOR",createdAt:"3"} ]->(page) MATCH (user3:users {id:"4"}) CREATE (user3)-[r3:MEMBER_OF {rId:"3",relation:"EMPLOYEE",createdAt:"4"} ]->(page) MATCH (user4:users {id:"5"}) CREATE (user4)-[r4:MEMBER_OF {rId:"4",relation:"FRIEND",createdAt:"5"} ]->(page) MATCH (user5:users {id:"6"}) CREATE (user5)-[r5:MEMBER_OF {rId:"5",relation:"EMPLOYEE",createdAt:"6"} ]->(page) MATCH (user6:users {id:"7"}) CREATE (user6)-[r6:MEMBER_OF {rId:"6",relation:"CO_WORKER",createdAt:"7"} ]->(page) MATCH (user7:users {id:"8"}) CREATE (user7)-[r7:MEMBER_OF {rId:"7",relation:"EMPLOYEE",createdAt:"8"} ]->(page) MATCH (user8:users {id:"9"}) CREATE (user8)-[r8:MEMBER_OF {rId:"8",relation:"EMPLOYEE",createdAt:"9"} ]->(page) MATCH (user9:users {id:"10"}) CREATE (user9)-[r9:MEMBER_OF {rId:"9",relation:"STUDENT",createdAt:"10"} ]->(page) RETURN r0

请提出实现此目标的有效且正确的方法。用户数组将从 REST API 获取

最佳答案

您可以将输入数据传递到密码查询中,如 parameters ,和walk through像这样的数组:

MATCH (page:pages {id: $pageId})
WITH page
UNWIND $users as userData
CREATE (user:users {id: userData.id})
CREATE (user)-[r:MEMBER_OF { rId: userdData.uuid,
relation: userData.role,
createdAt: userData.created_at
}]->(page)

关于node.js - 在单个密码查询nodejs中创建多个不同 Node 之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43754147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com