0

EDIT

When i am talking about node and node id i am specifically talking about the Neo4j representation of a node not node as in Node.js


I am building out an application on top of Neo with node using the thingdom wrapper on top of the REST API and i am attempting to add my own custom id property that will be a hash of the id to be used in the URL for example.

What i am currently doing is creating the node and then once the id is returned hashing this and saving it back to the node, so in effect i am calling the REST API twice to create a single node.

This is a long shot but is there a way to get a reliable next id from Neo using the REST API so that i can do this all in one request.

If not does anyone know of a better approach to what i am doing?

Modika
  • 6,192
  • 8
  • 36
  • 44

2 Answers2

2

The internal id of neo4j nodes is not supposed to be used for external interfaces, as noted in the documentation. That means especially it's not a good idea to try to guess the next id.

It's recommended to use application specific ids to reference nodes, if you use UUIDs (especially uuid type 4) there is only a minimal chance of collisions and you can compute them on node creation, before storing them in the database.

Thomas Fenzl
  • 4,342
  • 1
  • 17
  • 25
  • Hi Thomas thanks for the answer, the issue is uuid are not really what we are using, and we are using a simple hash of the id. Your approach makes sense and was what we initial went with but like i said we now use a hash instead of the id. The API is very early in creation and this may change again. – Modika Jul 05 '13 at 18:04
  • Then you will need the two calls, I think, as there is no sure way to tell what id you will get. – Thomas Fenzl Jul 05 '13 at 18:10
0

By curiosity, can I ask you why you need to have the Id stored in the Node?

But anyway, it's quite common in Node.js to call a succession of APIs. And you will see that with Neo4j it will be required more than once.

If you don't already use it, I can only suggest you to take a look at Async: https://github.com/caolan/async

And particularly to the "waterfall" method that allows you to call more than one API that use the result of the previous call.

Aurélien Thieriot
  • 5,853
  • 2
  • 24
  • 25
  • Hi, to be honest the code is abstracted enough for it not to need an ASync library yet, the callbacks are limited and if its too deep its factored out. I was simply looking for a way to not have to hit Neo twice. The idea of having it stored in the db would mean i could pull it all out in one go as apposed to regenerating it each time, but it is something to look at. – Modika Jul 03 '13 at 17:23