Star

Created With

linkFinding Nodes

Neogma provides some basic functionality for matching, filtering, limiting and ordering nodes. For more complex find statements, one can use the driver for running a raw query.

linkFinding Many Nodes

1link/* --> finds Users Nodes and returns an array of Users Instances */

2linkconst users = await Users.findMany({

3link /* --> the where param for matching the Nodes */

4link where: {

5link /* --> the name property of the User Nodes must be 'John' and their id must be in: ('1', '2') */

6link name: 'John',

7link /* --> using the "in" Symbol from "Op" */

8link id: { [Op.in]: ['1', '2'] },

9link },

10link /* --> (optional) the limit of this query */

11link limit: 3,

12link /* --> (optional) the skip of this query */

13link skip: 3,

14link /* --> (optional) the order of this query, in this case by: age DESC, id ASC */

15link order: [['age', 'DESC'], ['id', 'ASC']],

16link /* --> (optional, default false) returns an array of the plain properties, instead of Instances */

17link plain: false,

18link /* --> (optional) throws NeogmaNotFoundError if no nodes are found (results length 0) */

19link throwIfNoneFound: true,

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

21link session: null,

22link});

23link

24linkconsole.log(users[0].bar()); // "The name of this user is: John"

25linkconsole.log(users[0].age, users[0].id); // 45 "2"

26linkconsole.log(users[1].age, users[1].id); // 45 "3"

27linkconsole.log(users[2].age, users[2].id); // 38 "1"

linkFinding a single Node

1link/* --> finds a User Node and returns a Users Instances */

2linkconst user = await Users.findOne({

3link /* --> the where param for matching the Node */

4link where: {

5link /* --> the name property of the User Node must be 'John' */

6link name: 'John',

7link },

8link /* --> (optional) the order of this query, in this case by: id ASC */

9link order: [['id', 'ASC']],

10link /* --> (optional, default false) returns the plain properties, instead of Instance */

11link plain: false,

12link /* --> (optional) throws NeogmaNotFoundError if the node is not found */

13link throwIfNotFound: true,

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

15link session: null,

16link});

17link

18linkconsole.log(user.bar()); // "The name of this user is: John"

19linkconsole.log(user.id, user.age); // "1" 38

linkFinding nodes and relationships via the Model static

The findRelationships static can find related nodes via an Alias.

1linkconst relationships = await Users.findRelationships({

2link /* --> the alias of the relationship, as provided in the Model definition */

3link alias: 'Orders',

4link /* --> (optional) where parameters for the query */

5link where: {

6link /* --> (optional) where parameters of the source node (i.e. User) */

7link source: {

8link id: '1'

9link },

10link /* --> (optional) where parameters of the target node (i.e. Order) */

11link target: {

12link id: '2'

13link },

14link /* --> (optional) where parameters of the relationship between the nodes */

15link relationship: {

16link rating: 4

17link },

18link },

19link /* --> (optional) limits the query. It's useful when the purpose is to find whether a relationship exists */

20link limit: 1,

21link /* --> (optional) minimum hops for a variable length relationship */

22link minHops: 1,

23link /* --> (optional) maximum hops for a variable length relationship. The value Infinity can be used for no limit on the max hops */

24link maxHops: 1,

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

26link session: null,

27link});

28link

29linkconsole.log(relationships[0]?.source.id); // '1'

30linkconsole.log(relationships[0]?.target.id); // '2'

31linkconsole.log(relationships[0]?.relationship.rating); // 4

linkFinding nodes and relationships via the Instance method

The findRelationships method can find related nodes via an Alias. It's a wrapper for the corresponding static, while using the Instance as the source node.

1link/* --> let "user" be a Users instance with a primary field: id = '1' */

2linkconst relationships = await user.findRelationships({

3link /* --> the alias of the relationship, as provided in the Model definition */

4link alias: 'Orders',

5link /* --> (optional) where parameters for the query */

6link where: {

7link /* --> (optional) where parameters of the target node (i.e. Order) */

8link target: {

9link id: '2'

10link },

11link /* --> (optional) where parameters of the relationship between the nodes */

12link relationship: {

13link rating: 4

14link },

15link },

16link /* --> (optional) limits the query. It's useful when the purpose is to find whether a relationship exists */

17link limit: 1,

18link /* --> (optional) minimum hops for a variable length relationship */

19link minHops: 1,

20link /* --> (optional) maximum hops for a variable length relationship. The value Infinity can be used for no limit on the max hops */

21link maxHops: 1,

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

23link session: null,

24link});

25link

26linkconsole.log(relationships[0]?.source.id); // '1'

27linkconsole.log(relationships[0]?.target.id); // '2'

28linkconsole.log(relationships[0]?.relationship.rating); // 4

Finding NodesFinding Many NodesFinding a single NodeFinding nodes and relationships via the Model staticFinding nodes and relationships via the Instance method

Introduction Getting Started

Modelschevron_right

Sessions and Transactions

Query Builderchevron_right
Query Runnerchevron_right

Bind Parameters

Where Parameters