Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-24-2021 07:41 PM
Hi All,
I am converting a (let's say relational) system into Neo. In the current system, we generate a unique ID for each new row. The ID is only 5 digits, alpha numeric e.g. '01BJF' and is generated sequentially (the next id would be '01BJG') and is globally unique across all types of rows. This Id is also immutable on each row and the IDs are not re-used.
Moving across to Neo4j, I know I could easily use GUID's as the ID on new nodes however our business folks have become very attached to their 5 digit ID's and they are rolled into all sorts of fixed length identification and accession numbers and printed on test tubes etc... so we need to keep them.
In Neo4j, I can only see 2 options.
In both cases, I think I would need to store the 'last ID generated' in some sensible global place (maybe as a property on a single utility node?) and increment this when I generate the next one or many ID's.
Any help appreciated with this. Which of my options is simplest? where would I store my 'last ID generated'? have I got this completely wrong?
Regards,
Michael
Solved! Go to Solution.
05-26-2021 02:23 AM
Hi Michael,
welcome to the Neo4j community!
Interesting task you got there. When reading your post, I also directly thought about a mix of the solutions that you suggested yourself. So, what I would do is:
To maybe give you a better insight in how that would work, here are some code bits that I have in mind:
1 - The user defined function would be called something like that:
MATCH (i: IdNode)
CREATE (b:Business)
SET b.businessId = myProcedure.getNextId(i.id)
2 - The user defined function would then be something like
@UserFunction
public Long getNextId(Long id){
...
return newId;
}
I hope this helps you.
Regards,
Elena
05-26-2021 02:23 AM
Hi Michael,
welcome to the Neo4j community!
Interesting task you got there. When reading your post, I also directly thought about a mix of the solutions that you suggested yourself. So, what I would do is:
To maybe give you a better insight in how that would work, here are some code bits that I have in mind:
1 - The user defined function would be called something like that:
MATCH (i: IdNode)
CREATE (b:Business)
SET b.businessId = myProcedure.getNextId(i.id)
2 - The user defined function would then be something like
@UserFunction
public Long getNextId(Long id){
...
return newId;
}
I hope this helps you.
Regards,
Elena
05-30-2021 05:52 PM
Thanks for the feedback Elena, this is very helpful and aligns perfectly with what I was thinking. Great minds think alike 😉
Michael
06-02-2021 08:36 PM
Hi @elena.kohlwey I have this working now.. thanks for the feedback. One thing though in your response, you didn't update the id node...this is what I am doing roughly
MATCH (i: IdNode)
SET i.id = myProcedure.getNextId(i.id)
CREATE (b:Business)
SET b.businessId = i.id
So I'm updating the Id node in place, then using the updated id value in my create
06-07-2021 12:22 AM
Yep, sounds good. Of course it needs to be updated :-).
All the sessions of the conference are now available online