cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Check Date Against list of Dates

MuddyBootsCode
Graph Steward

I'm trying to wrangle some data here. I've got a relationship set up that looks like:

(:Well {lastProdDate: Date})-[:ON]->(:Abstract {name: Name})

I'm trying to single out abstracts that have wells where 100% of the production is earlier than a certain date. So far I've got:

WITH DATE("2019-01-01") as endDate
MATCH (w:Well)-[:ON]->(a:Abstract)
With Collect(w.lastProdDate) as dates

After that I need to loop through the dates and return only abstracts where all dates are less than endDate. Any one done anything similar?

1 ACCEPTED SOLUTION

MATCH (a:Abstract {name: Name})
WHERE ALL( w IN [(w)-[:ON]->(a) | w] WHERE w.lastProdDate > $date)
RETURN a

or

MATCH (a:Abstract {name: Name})
WHERE size( ()-[:ON]->(a)) = size[(w)-[:ON]->(a) WHERE w.lastProdDate > $date | w])
RETURN a

View solution in original post

3 REPLIES 3

ameyasoft
Graph Maven

WITH DATE("2019-01-01") as endDate
MATCH (w:Well)-[:ON]->(a:Abstract)
WHERE w.lastProdDate <= endDate
With Collect(w.lastProdDate) as dates

Without WITH,
WHERE w.lastProdDate <= "2019-01-01"

That's not quite it, it does indeed return a collection of the dates that match that criteria but it doesn't return only the collections where all pass. You've got me closer though, thank you!

MATCH (a:Abstract {name: Name})
WHERE ALL( w IN [(w)-[:ON]->(a) | w] WHERE w.lastProdDate > $date)
RETURN a

or

MATCH (a:Abstract {name: Name})
WHERE size( ()-[:ON]->(a)) = size[(w)-[:ON]->(a) WHERE w.lastProdDate > $date | w])
RETURN a