data= {
"id": 1,
"name": "samuel",
"Manager": [
{
"id": "",
"name": "manager1",
"approvers": [325,134],
}
]
}
对于这个数据对象,我们在Neo4j中使用类似的给定cypher查询来执行add函数
query = "CREATE CONSTRAINT ON (users:user) ASSERT users.name IS UNIQUE";
return cypher(
{
"query": query
}
).then(function () {
query = "CREATE (user:user{ name:"samuel "})
"RETURN user";
action = "create";
return cypher(
{
"query": query,
});
}).then(function (data) {
userId = data[0].user._id;
return Promise.each(data.manager, function (entry) {
query = "MATCH (user: user) WHERE id(user) = " + userId + " " +
" OPTIONAL MATCH (managerApprovers:user) WHERE id(managerApprovers) IN [325,134] " +
"CREATE (manager: managernode {name: "manager1"})<-[:HAS_MANAGER]-(user) " +
"FOREACH (a IN CASE WHEN managerApprovers IS NOT NULL THEN [managerApprovers] ELSE [] END | " +
"CREATE (managerApprovers)<-[:HAS_MANAGE_APPROVER]-(managernode)) RETURN user,managernode";
return cypher(
{
"query": query,
}).then(function (data) {
{
res.action = action;
res.result = data;
return res;
});
}
如果我们想要更新用户名以及更新管理器详细信息和关系HAS_MANAGE_APPROVER,HAS_MANAGER如何在Neo4j中执行
答案 0 :(得分:1)
您必须MATCH
关系,将其存储在变量中,然后SET
您想要的属性:
Match (a:firstNode)-[relation:MY_RELATIONSHIP]->(b:secondNode)
SET relation.variable="Foo"
请注意,建议不要使用neo4j内部ID,请参阅Should we use the Neo4J internal id?