Reputation: 142
data= {
"id": 1,
"name": "samuel",
"Manager": [
{
"id": "",
"name": "manager1",
"approvers": [325,134],
}
]
}
FOR this data object , we did the add function using a similar given cypher query in Neo4j
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;
});
}
if we want to update the user name along with updating the manager details and the relation HAS_MANAGE_APPROVER,HAS_MANAGER how is it performed in Neo4j
Upvotes: 1
Views: 87
Reputation: 8731
You have to MATCH
the relation, store it in a variable and then SET
the property you want:
Match (a:firstNode)-[relation:MY_RELATIONSHIP]->(b:secondNode)
SET relation.variable="Foo"
Keep in mind that using neo4j internal ID is not recommended, see Should we use the Neo4J internal id?
Upvotes: 1