Solutions for modifying relationship information in Neo4j with cypher expressions

data= {
              "id": 1,
               "name": "samuel",
               "Manager": [
                    {
                        "id": "",
                        "name": "manager1",
                        "approvers": [325,134],

                            }
                      ]
                    }

In relation to the above data structure, we executed an add function using a corresponding 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 need to update the user's name along with updating the manager details and the relationship HAS_MANAGE_APPROVER, HAS_MANAGER, this is how it is accomplished in Neo4j.

Answer №1

To effectively manage the relationship, you must first identify a match, assign it to a variable, and then update the desired property:

Match (a:firstNode)-[relation:MY_RELATIONSHIP]->(b:secondNode)
SET relation.variable="Foo"

It is important to note that relying on the neo4j internal ID is discouraged; additional information can be found at Should we use the Neo4J internal id?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue duplicating DIV elements using jQuery's clone() method causes button duplication error

Just starting out with programming, so my code might not be perfect. I'm encountering an issue when I click a button in the HTML (Fiddle) $(document).ready(function() { $("button").click(function() { $(".groupcontainer").clone().appendTo(".grou ...

Trouble Loading TypeScript Class in Cast Situation

I've encountered an issue with my TypeScript model while using it in a cast. The model does not load properly when the application is running, preventing me from accessing any functions within it. Model export class DataIDElement extends HTMLElement ...

Encountering error ORA-12514 when utilizing the node oracle-db npm package

At the moment, I am immersed in a project that relies on utilizing oracle for its backend. Following the instructions provided in this link, I successfully installed node-oracledb on my Mac using npm. The contents of my file are as follows: var oracledb = ...

Converting an object with a combination of different index types into a string representation

I'm dealing with a unique object structure that behaves similarly to an array, except it contains a mix of index types (numbers and strings). Here's an example: var myObj = []; myObj[0] = 'a'; myObj[1] = 'b'; myObj[2] = &apos ...

Having trouble retrieving mobiscroll instance in Angular with Ionic

I'm facing an issue with accessing the instance of my mobiscroll widget in Angular 4 with Ionic Framework. Despite following all the correct steps, the actual widget won't get selected. Below is the code for the widget: <mbsc-widget [options ...

Is there a way to eliminate the bottom padding in a textarea field?

Need help removing the bottom padding in a textarea? Check out this code snippet: $('textarea').css("height", $("textarea").prop("scrollHeight")) textarea { width: 300px; resize: none; margin: 0; padding: 0; } <script src="https://a ...

Is it possible to transform a webpack configuration into a Next.js configuration?

i have come across a webpack configuration setup from https://github.com/shellscape/webpack-plugin-serve/blob/master/recipes/watch-static-content.md: const sane = require('sane'); const { WebpackPluginServe: Serve } = require('webpack-plugin ...

Vue component does not refresh when data changes unless using the :key attribute

I have been encountering an interesting issue with my simple breadcrumbs component in the app. Despite having a data property called pickedTable, the component fails to re-render when this data changes. However, by adding the :key="pickedTable" attribute, ...

What is the best way to integrate Babel and React into my Express Application?

I must admit, I am a bit of a newbie when it comes to this, but I've been doing a lot of research trying to make this work with no luck so far. I enjoy working on my apps in Express and now I want to incorporate React for some of my reusable componen ...

Enable jquery offsetParent() function

$(document).ready(function(){ $("button").click(function(){ if ($("p").offsetParent().css("background-color") === "red") { $("p").offsetParent().css("background-color", "yellow"); } else { $("p").offsetParent().c ...

"The magic of ReactJS's virtual DOM lies in its ability to keep a lightweight representation

Stumbled upon this statement in some form while browsing the web Whenever the data underlying a React application changes, a new Virtual DOM representation of the user interface is generated. This is where things start to get interesting. Updating the b ...

Invoke a jQuery function in the parent page using regular JavaScript from an iframe

I have successfully created an iframe using regular javascript. Inside the iframe is a Jquery function along with JQuery itself and it functions correctly within the iframe. However, I am now looking to execute this function from the parent page instead of ...

How can I set up multiselect values in AngularJS ui-select?

Solution: Success! I managed to resolve the issue by implementing this solution and creating a customized build of the ui-select. Hopefully, this fix will be incorporated into the official master branch soon! Issue Is there a way to set up a select elem ...

The search functionality in an Html table is currently malfunctioning

Currently, I am working on developing a search mechanism in HTML. It seems to be functioning properly when searching for data for the first time. However, subsequent searches do not yield the expected results. Additionally, when trying to search with empty ...

Is there a method to update the status of a Jquery UI Mobile navbar using Javascript?

I have created a navigation bar using the Jquery mobile UI 1.01 framework; <div id="footer" data-role="footer" data-position="fixed"> <div data-role="navbar"> <ul> <li><a href="#" onClick="toggle_units();" clas ...

What is the recommended way to include an image in a v-for loop in Vue.js?

I have attempted various online solutions, but I am still unable to display images on the screen. Could it be a simple mistake? The file names and folders are accurate. When providing the path, I aim to retrieve the image associated with the sub-club name ...

What is the most efficient way to cycle through HTML image elements and display a unique random image for each one?

I'm currently working on coding a simple game that involves guessing the Hearthstone card based on its flavor text. I plan to add a button later to progress in the game, but I haven't implemented that yet. To start, I created 4 image elements an ...

Utilizing Google Web Fonts in Gatsby with Custom Styled Components

While using createGlobalStyle from styled-components for global styling, everything seems to be working fine except for applying Google fonts. I have tried multiple ways but can't seem to get it to work. Here's the code snippet: import { createG ...

Looking for a way to replicate the functionality of a switch case within an object literal function

When working with a switch case, the default case handles any scenarios that are not covered by the expected cases. To simplify my code and reduce cyclomatic complexity, I ended up replacing the switch case with an object literal function. function test() ...

How can Angular hide a global component when a particular route is accessed?

Is it possible to hide a global component in Angular when a specific route is opened? For instance, consider the following code: app.component.html <app-header></app-header> <app-banner></app-banner> <!-- Global Component I w ...