node-neo4j v2 is a ground-up rewrite of node-neo4j, partly to take advantage of Neo4j 2.0's re-design, and partly to incorporate lessons learned from v1.
node-neo4j v2's big new features and changes are:
-
An emphasis on Cypher now (no more individual CRUD methods like v1's
db.createNode
). For anything non-trivial, Cypher is much more robust and expressive, so writing it directly is highly encouraged. -
Support for Cypher transactions and batching, as well as arbitrary HTTP requests (including streaming support) and custom headers.
-
First-class support for Neo4j 2.0 labels, schema indexes, and constraints, as well as Neo4j 2.2's password-based auth.
-
Much better error handling, differentiating between client, server, and transient errors.
-
Much better test coverage.
-
An options-based API now, rather than multiple parameters per function, for better readability and more extensibility.
For details on all these features and more, be sure to read through the readme.
If you're currently running node-neo4j v1, you may have to make some significant changes to your code, but hopefully the above features make it worth it. =)
Simple changes:
-
db.query(query, params, callback)
is nowdb.cypher({query, params}, callback)
-
node.id
andrel.id
are nownode._id
andrel._id
- This is because using these Neo4j internal IDs is officially discouraged now. Better to use a unique property instead (e.g.
username
oruuid
).
- This is because using these Neo4j internal IDs is officially discouraged now. Better to use a unique property instead (e.g.
-
node.data
andrel.data
are nownode.properties
andrel.properties
Removed CRUD methods (use Cypher instead):
-
db.createNode
andnode.createRelationshipTo
/From
-
db.getNodeById
anddb.getRelationshipById
-
node.getRelationships
andnode.getRelationshipNodes
-
node.incoming
,node.outgoing
,node.all
, andnode.path
-
node.save
andrel.save
- In general,
Node
andRelationship
instances are no longer "stateful". Instead of making changes to the database by modifying properties on these instances and callingsave
, just make changes via Cypher directly. Much more robust, precise, and expressive. Note in particular thatSET node += {props}
lets you update some properties without overwriting others.
- In general,
-
node.exists
andrel.exists
- Since
Node
andRelationship
instances are no longer stateful, node-neo4j v2 only ever returns instances for data returned from Neo4j. So these nodes and relationships always "exist" (at least, at the time they're returned).
- Since
-
node.del(ete)
andrel.del(ete)
Removed legacy index management (use schema indexes instead):
-
db.createNodeIndex
anddb.createRelationshipIndex
-
db.getNodeIndexes
anddb.getRelationshipIndexes
-
db.getIndexedNode(s)
anddb.getIndexedRelationship(s)
-
db.queryNodeIndex
anddb.queryRelationshipIndex
-
db.deleteNodeIndex
anddb.deleteRelationshipIndex
-
node.(un)index
andrel.(un)index
Removed miscellaneous:
-
rel.start
andrel.end
- These used to be full Node instances, but it's no longer efficient to load full node data for all relationships by default, so only
rel._fromId
andrel._toId
exist now. Expand your Cypher query to return full nodes if you need them.
- These used to be full Node instances, but it's no longer efficient to load full node data for all relationships by default, so only
-
Path
class- For similar reasons as
rel.start
andrel.end
. Expand your Cypher query to returnNODES(path)
orRELATIONSHIPS(path)
if you need them.
- For similar reasons as
-
db.execute
(for Gremlin scripts)- Gremlin has been dropped as a default plugin in Neo4j 2.x, and Cypher is clearly the recommended query language going forward. If you do need Gremlin support, you can always make HTTP requests to the Gremlin endpoint directly.
-
db.reviveJSON
anddb.fromJSON
- We may add these back if needed, but for now, since
Node
andRelationship
instances are no longer stateful (they don't even have any public methods), reviving JSON isn't really needed. You can stillJSON.stringify
nodes and relationships, and you should be able to use parsed JSON objects directly.
- We may add these back if needed, but for now, since
-
Streamline futures (TODO: Promises instead?)
- This library is no longer written in Streamline, so methods no longer return Streamline futures. If your app isn't written in Streamline, this likely never mattered to you. But even if your app is written in Streamline, this change may not matter to you, as Streamline 1.0 lets you call any async function with
!_
.
- This library is no longer written in Streamline, so methods no longer return Streamline futures. If your app isn't written in Streamline, this likely never mattered to you. But even if your app is written in Streamline, this change may not matter to you, as Streamline 1.0 lets you call any async function with
node-neo4j-template PR #18 is a good model for the changes needed (most notably commit bbf8e86
). Take a look through that, and if you run into any issues migrating your own code, feel free to reach out for help. Good luck!
See the full v1 changelog »