I have a graph containing nodes of two types: Attractions and Hotels.
What I want to do is that query for Hotels that are surrounded by three Attractions. The query I have now (below) gives Hotels that are connected to at least one Attraction.
FOR document IN Attraction
FOR vertex, edge, path IN 1..2 OUTBOUND document GRAPH "LondonAttractionDB"
FILTER path.vertices[0].entityTypes[0] == "Attraction" OR path.vertices[0].entityTypes[0] == "Attraction" OR path.vertices[0].entityTypes[0] == "Attraction"
FILTER path.vertices[1].entityTypes[0] == "Hotel"
FOR prop4 IN path.edges[0].properties
FILTER prop4.name == "name" AND prop4.value == "Food_and_beverage_location"
OR prop4.name == "name" AND prop4.value == "Food_and_beverage_location"
OR prop4.name == "name" AND prop4.value == "Accommodation_location"
RETURN DISTINCT path
This gives the following result. (Orange - Hotel, Green - Attraction)
How do I get the result shown within circles? (Hotels connected to exactly three attractions)
Any help is much appreciated.
It's difficult to answer without details about the dataset (document structure and collections), but based on your example query and description, I would use a different approach:
FOR hotel IN Attraction
FILTER doc.entityTypes[0] == "Hotel"
LET attractions = (
FOR vertex IN 1..1 INBOUND hotel GRAPH "LondonAttractionDB"
FILTER vertex.entityTypes[0] == "Attraction"
RETURN 1
)
FILTER LENGTH(attractions) == 3
RETURN hotel