i have a dataset where company node a1,a2,a3,.....a10, and the relationship connects between the nodes has property of edge name and date. and i check that the date is in datetime format.
now i want to write a query to find all paths from a1 to a3 with 3 jumps and the month of date is in may.
MATCH path = (start:Company {name: 'a1'})-[r:INTERACTS*3]->(end:Company )
where DateTime(r.date).month = 5
RETURN path
but it would give me error saying :
Type mismatch: expected Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was List (line 2, column 16 (offset: 89))
"where DateTime(r.date).month = 5
but if i remove the where condition but with jump condition 3 :
MATCH path = (start:Company {name: 'a1'})-[r:INTERACTS3]->(end:Company )
RETURN path
or if i remove the *3 but remain with date condition
MATCH path = (start:Company {name: 'a1'})-[r:INTERACTS]->(end:Company )
where DateTime(r.date).month = 5
RETURN path
it would both work fine. But if i want to combine both date condition and jump = 3, it wouldnt work. i would like to know why. or is there wrong with my code? please advise! thanks
βrβ is a list in your query, so you are getting a type mismatch error. You could do something like the following.
MATCH path = (start:Company {name: 'a1'})-[r:INTERACTS*3]->(end:Company )
where all(i in r where DateTime(i.date).month = 5)
RETURN path
This requires all potential paths to be found first, then each is filtered. It would be more efficient to use qualified paths, as each segment will be evaluated with your condition as the path is expanded.
MATCH path = (start:Company {name: 'a1'})( ()-[r:INTERACTS]->() where DateTime(r.date).month = 5){1,3}(end:Company)
RETURN path
BTW- why don't you store r.date in date format so you don't have to convert it each time you want to use it in a predicate?
i think i have converted the date into datetime, i see that my date in neo4j is in this format: "2020-01-07T00:00:00Z", or is this the correct datetime format?
but when i tried to do date filtering, if i just specify date > '2020-01-05' or date > 2020-01-05, it would give me no changes or no path,
MATCH path = (start:Company {name: 'a1'})-[r:INTERACTS*2]->(end:Company {name: 'a3'})
where all(i in r where (i.date)> '2023-05-15')
RETURN path
so i choose to use DateTime(r.date).month = 5 for the filtering.
It does seem like it is stored as a DateTime value. The example you presented represents midnight with no offset from UTC time . You probably set the property withdatetime(β2020-01-07β), thus adding the midnight time component since time was not provided. You could have use βdateβ instead if you knew you would never have included time.
If it is truly a DateTime value, then the following expression should work:
r.date.month = 5
The reason those expressions did not work is because the property is a DateTime and you are comparing it to a strip representation of a date. You should have done something like: