(Quick Reference)

4 Enhancements to Neo4j core API - Reference Documentation

Authors: Stefan Armbruster

Version: 1.0.0

4 Enhancements to Neo4j core API

Inspired by a Github issue ticket the Neo4j Grails contains some enhancements to the Neo4j core API. These enhancements are implemented using Groovy's ExpandoMetaClass.

setting properties on nodes/relationships

Assigning an arbitrary property onto a Neo4j node or relationship can be simply done by using Groovy's property mechanism:

def node = graphDatabaseService.createNode()
node.myProperty = myValue

The same words for getting properties:

def node = …
def value = node.myProperty

There is a important convention: when the property ends with "Date" then a date type is assumed. The node property then helds respective millis.

JSON marshalling

Neo4j nodes and relationships can be easily marshalled to JSON, e.g. in a controller using:

def node = graphDatabaseService.getNodeById(myid)
render node as JSON