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) the order of the results. The 'on' property specifies the entity context: 'source', 'target', or 'relationship' */

20link order: [

21link {

22link on: 'relationship',

23link property: 'rating',

24link direction: 'DESC',

25link },

26link {

27link on: 'target',

28link property: 'date',

29link direction: 'ASC',

30link }

31link ],

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

33link limit: 1,

34link /* --> (optional) skips the specified number of records. Useful in combination with 'limit' for pagination */

35link skip: 10,

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

37link minHops: 1,

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

39link maxHops: 1,

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

41link session: null,

42link});

43link

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

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

46linkconsole.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) the order of the results. Use 'on' to apply sorting to the 'source', 'target', or 'relationship' */

17link order: [

18link {

19link on: 'relationship',

20link property: 'rating',

21link direction: 'DESC',

22link },

23link {

24link on: 'target',

25link property: 'date',

26link direction: 'ASC',

27link }

28link ],

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

30link limit: 1,

31link /* --> (optional) skips the specified number of records. Useful in combination with 'limit' for pagination */

32link skip: 10,

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

34link minHops: 1,

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

36link maxHops: 1,

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

38link session: null,

39link});

40link

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

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

43linkconsole.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