Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-04-2021 10:09 AM
After having attended the Graph Modeling class, I'm looking to optimize a graph I'm using that tracks product expiration dates. Originally I had the expiration date as a property of the product, but in reviewing the materials from the Graph Modeling class, it seems to make sense to create an Expiration Date node. not only for performance reasons, but also to show additional clusters of products expiring. I can obviously create an Expiration Date node with a year value, but I'm looking at a year and month (YYYY-MM). Does this make sense?
Secondly, I'm having issues extracting just the year and month from the existing date field (actual date) to use for the new Expiration Date node. Any suggestions on approaches for just this format?
Thanks in advance.
Solved! Go to Solution.
11-04-2021 01:41 PM
I'm pulling the date from the product node (actual date, not a string representation) and then creating a new date node with just the year and month. The solution I had wasn't elegant but it worked for what I needed. I can now see all the products related to a date node. It traverses quicker than just using a date property in the Product node and pattern (things expiring in the same time frame) now shows up with the relationship.
This is the script I used:
MATCH (p:PRODUCT)
MERGE (eos:EOS_DATE {EOS_Date: toString(p.EOS_Date.year) + '-' + toString(p.EOS_Date.month)})
MERGE (p)-[:END_OF_SUPPORT]->(eos)
RETURN eos, p
11-04-2021 11:45 AM
I found a partial solution by using a ".year" on the end of my date property to just return the year. Is there a way to make it year and month? The source property is a date type (YYYY-MM-DD).
11-04-2021 01:09 PM
I found a way to do this through a toString conversion. it gets me what I needed.
11-04-2021 01:26 PM
or what about
return date(date()).year + '' + date(date()).month;
+---------------------------------------------+
| date(date()).year + '' + date(date()).month |
+---------------------------------------------+
| "202111" |
+---------------------------------------------+
11-04-2021 01:41 PM
I'm pulling the date from the product node (actual date, not a string representation) and then creating a new date node with just the year and month. The solution I had wasn't elegant but it worked for what I needed. I can now see all the products related to a date node. It traverses quicker than just using a date property in the Product node and pattern (things expiring in the same time frame) now shows up with the relationship.
This is the script I used:
MATCH (p:PRODUCT)
MERGE (eos:EOS_DATE {EOS_Date: toString(p.EOS_Date.year) + '-' + toString(p.EOS_Date.month)})
MERGE (p)-[:END_OF_SUPPORT]->(eos)
RETURN eos, p
All the sessions of the conference are now available online