Star

Created With

linkUpdating Nodes and Relationships

Apart from saving an existing Instance, each model provides functions to directly update nodes or relationships.

linkUpdating Nodes

Nodes can be updated directly by providing the properties to be set, providing property update operators, and a where parameter to match the nodes.

1linkconst result = await Users.update(

2link {

3link /* --> updates the nodes to set their name to 'Bob' */

4link name: 'Bob',

5link /* --> using the "remove" Symbol from "UpdateOp" */

6link age: { [UpdateOp.remove]: true },

7link },

8link {

9link /* --> (optional) a where parameter to match nodes */

10link where: {

11link /* --> nodes with the id '1' will be matched */

12link id: '1',

13link },

14link /* --> (optional, default false) whether to return the values of the nodes after the update */

15link return: true,

16link /* --> (optional) an existing session or transaction to use */

17link session: null,

18link },

19link);

20link

21link/* --> ONLY if 'return' is set to true. The Instances of the matched and updated nodes. If 'return' is set to false, this will be an empty array */

22linkconst instances = result[0];

23linkconsole.log(instances[0].name); // "Bob"

24linkconsole.log(instances[0].age); // undefined

25link

26link/* --> the QueryResult from the neo4j driver */

27linkconst queryResult = result[1];

linkUpdating relationship properties via the Model static

Relationship properties can be updated directly by providing the values to be set, the relatioship alias, and an optional where parameter to match the source nodes, target nodes and relationships.

1linkawait Users.updateRelationship(

2link {

3link /* --> sets the 'rating' property of the relationship to the following */

4link rating: 5,

5link },

6link {

7link /* --> used the 'Orders' alias for the relationship configuration, as provided in the Model definition */

8link alias: 'Orders',

9link /* --> (optional) where parameters for matching the nodes or the relationship */

10link where: {

11link /* --> the source node(s) (User) is matched to have the following name */

12link source: {

13link name: 'Bob',

14link },

15link /* --> the target node(s) (Order) is matched to have the following id */

16link target: {

17link id: '2',

18link },

19link /* --> the relationship(s) between the source and the target node(s) are matched to have the following 'rating' */

20link relationship: {

21link rating: 4,

22link },

23link },

24link /* --> (optional) an existing session or transaction to use */

25link session: null,

26link },

27link);

linkUpdating relationship properties via the Instance method

Similar to the Model static, relationship properties can be updated directly by providing the values to be set, the relatioship alias, and an optional where parameter to match the target nodes and relationships. The source node will always be the one that corresponds to the instance, and its primary key field must be set.

1link/* --> let 'user' be a Users Instance. It's used as the source node */

2linkawait user.updateRelationship(

3link {

4link /* --> sets the 'rating' property of the relationship to the following */

5link rating: 5,

6link },

7link {

8link /* --> used the 'Orders' alias for the relationship configuration, as provided in the Model definition */

9link alias: 'Orders',

10link /* --> (optional) where parameters for matching the nodes or the relationship */

11link where: {

12link /* --> the target node(s) (Order) is matched to have the following id */

13link target: {

14link id: '2',

15link },

16link /* --> the relationship(s) between the source and the target node(s) are matched to have the following 'rating' */

17link relationship: {

18link rating: 4,

19link },

20link },

21link /* --> (optional) an existing session or transaction to use */

22link session: null,

23link },

24link);

Updating Nodes and RelationshipsUpdating NodesUpdating relationship properties via the Model staticUpdating relationship properties via the Instance method

Introduction Getting Started

Modelschevron_right

Sessions and Transactions

Query Builderchevron_right
Query Runnerchevron_right

Bind Parameters

Where Parameters