Search code examples
grapharangodbaql

Get count in graph traversal


I started learning arangoDB, I took the udemy course to learn the basics of arangoDB. The instructor used flights & airport dataset to teach both named & anonymous graph queries. One of the queries that he ran to fetch the list of airports was

FOR airport IN airports FILTER airport.city =="San Francisco" FILTER airport.vip == true FOR v,e,p IN 1..1 OUTBOUND airport flights FILTER v._id=="airports/KOA" LIMIT 0,10 return p

what if I want to fetch count of all possible result, what would be the best approach to get the count.


Solution

  • You could encapsulate the query in the COUNT function:

    RETURN COUNT(
        FOR airport IN airports 
            FILTER airport.city =="San Francisco" AND airport.vip == true 
            FOR v,e,p IN 1..1 OUTBOUND airport flights 
                FILTER v._id=="airports/KOA" LIMIT 0,10 
                RETURN 1
    )