Class: Node

Defined in: lib/Node._coffee
Inherits: PropertyContainer

Overview

The class corresponding to a Neo4j node.

Property Summary

Properties inherited from PropertyContainer

self, exists, id, data

Instance Method Summary

Inherited Method Summary

Methods inherited from PropertyContainer

#equals, #delete, #del, #toJSON

Instance Method Details

- (String) toString()

Return a human-readable string representation of this node, suitable for development purposes (e.g. debugging).

Returns:

  • String

- (Node) save(_)

Persist or update this node in the database. "Returns" (via callback) this same instance after the save.

Parameters:

  • callback (Function)

Returns:

- (void) delete(_, force = false)

Note: For safety, it's recommended to not pass the force flag and instead manually and explicitly delete known relationships beforehand.

Delete this node from the database. This will throw an error if this node has any relationships on it, unless the force flag is passed in, in which case those relationships are also deleted.

Parameters:

  • callback (Function)
  • force (Boolean) If this node has any relationships on it, whether those relationships should be deleted as well.

- (void) index(index, key, value, _)

Add this node to the given index under the given key-value pair.

Parameters:

  • index (String) The name of the index, e.g. 'users'.
  • key (String) The key to index under, e.g. 'username'.
  • value (String) The value to index under, e.g. 'aseemk'.
  • callback (Function)

- (void) unindex(index, key, value, _)

Delete this node from the given index, optionally under the given key or key-value pair. (A key is required if a value is given.)

Parameters:

  • index (String) The name of the index, e.g. 'users'.
  • key (String) (Optional) The key to unindex from, e.g. 'username'.
  • value (String) (Optional) The value to unindex from, e.g. 'aseemk'.
  • callback (Function)

- (Relationship) createRelationshipTo(otherNode, type, data, cb)

Create and "return" (via callback) a relationship of the given type, and optionally with the given properties, from this node to another node.

Parameters:

  • otherNode (Node)
  • type (String)
  • data (Object) (Optional) The properties this relationship should have.
  • callback (Function)

Returns:

- (Relationship) createRelationshipFrom(otherNode, type, data, cb)

Create and "return" (via callback) a relationship of the given type, and optionally with the given properties, from another node to this node.

Parameters:

  • otherNode (Node)
  • type (String)
  • data (Object) (Optional) The properties this relationship should have.
  • callback (Function)

Returns:

- (Array<Relationship>) getRelationships(type, _)

Fetch and "return" (via callback) the relationships of the given type or types from or to this node.

Parameters:

  • type (String, Array<String>)
  • callback (Function)

Returns:

- (Array<Relationship>) outgoing(type, _)

Fetch and "return" (via callback) the relationships of the given type or types from this node.

Parameters:

  • type (String, Array<String>)
  • callback (Function)

Returns:

- (Array<Relationship>) incoming(type, _)

Fetch and "return" (via callback) the relationships of the given type or types to this node.

Parameters:

  • type (String, Array<String>)
  • callback (Function)

Returns:

- (Array<Relationship>) all(type, _)

TODO: This aliases #getRelationships, but is that redundant?

Fetch and "return" (via callback) the relationships of the given type or types from or to this node.

Parameters:

  • type (String, Array<String>)
  • callback (Function)

Returns:

- (Array<Node>) getRelationshipNodes(rels, _)

TODO: This could/should probably be renamed e.g. getAdjacentNodes().

Fetch and "return" (via callback) the nodes adjacent to this one following only relationships of the given type(s) and/or direction(s).

Parameters:

  • rels (String, Array<String>, Object, Array<Object>) This can be a string type, e.g. 'likes', in which case both directions are traversed. Or it can be an array of string types, e.g. ['likes', 'loves']. It can also be an object, e.g. {type: 'likes', direction: 'out'}. Finally, it can be an array of objects, e.g. [{type: 'likes', direction: 'out'}, ...].
  • callback (Function)

Returns:

- (Path) path(to, type, direction, maxDepth = 1, algorithm = 'shortestPath', _)

TODO: Support other algorithms, which may require extra parameters, by changing this method to take an options object.
TODO: Support multiple relationship types/directions?

Fetch and "return" (via callback) the shortest path, if there is one, from this node to the given node. Returns null if no path exists.

Parameters:

  • to (Node)
  • type (String) The type of relationship to follow.
  • direction (String) One of 'in', 'out', or 'all'.
  • maxDepth (Number) The maximum number of relationships to follow when searching for paths. The default is 1.
  • algorithm (String) This needs to be 'shortestPath' for now.
  • callback (Function)

Returns: