Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. # IT:ArangoDB:HowTo:API/JS/Graphs/Paths # <callout type="Navigation" class="small"> * [[../|(UP)]] {{indexmenu>.#2|nsort tsort}} </callout> <panel title="Summary"> We already touched on the very simple edge collection specific methods: * [[IT/AD/ArangoDB/HowTo/API/JS/Graphs/Edges]] As well as stating that the PATH method offers a lot more options. </panel> ## Process ## ### Searching for Direct Relationships (Path Length of 1) <sxh javascript> //Create a Statement to search for Paths //that have a Start/Source of X, //and a length of 1 (ie, direct friends of X) //and return just the name stmt = db._createStatement( { "query" : "FOR p IN PATHS(users, knows,'outbound') FILTER p.source._id == @id && LENGTH(p.edges) == 1 RETURN p.vertices[*].name" }); stmt.bind("id", carla._id); cursor = stmt.execute(); while (cursor.hasNext()) { print(cursor.next()); } </sxh> ### Searching for Friends of Friends (Path Length of 2) <sxh javascript> //create a statement for //Paths with a start/source of X //and length larger than 1 (ie not direct friends) //and return just the name. stmt = db._createStatement( { "query" : "FOR p IN PATHS(users, knows, 'outbound') FILTER p.source._id == @id && LENGTH(p.edges) 2 RETURN p.vertices[*].name" }); stmt.bind("id", carla._id); cursor = stmt.execute(); while (cursor.hasNext()) { print(cursor.next()); } </sxh> ### Searching for all InDirect Relationships (Path Length of >1) <sxh javascript> //create a statement for //Paths with a start/source of X //and length larger than 1 (ie not direct friends) //and return just the name. stmt = db._createStatement( { "query" : "FOR p IN PATHS(users, edges, 'outbound') FILTER p.source._id == @id && LENGTH(p.edges) > 1 && LENGTH(p.edges) < 7 RETURN p.vertices[*].name" }); stmt.bind("id", carla._id); cursor = stmt.execute(); while (cursor.hasNext()) { print(cursor.next()); } </sxh> #### Who knows X <sxh javascript> //Changing 'outbound' to 'inbound' //create a statement for Paths //with source/start of X, and length 1 //returning the terminal vertex (the second vertex...) stmt = db._createStatement( { "query" : "FOR p IN PATHS(users, knows, 'inbound') FILTER p.source._id == @id && LENGTH(p.edges) == 1 RETURN p.vertices[1].name" }); stmt.bind("id", carla._id); cursor = stmt.execute(); while (cursor.hasNext()) { print(cursor.next()); } </sxh> ## Resources ## * https://www.arangodb.org/2013/01/31/querying-documents-and-graphs-in-one-database-with-aql-easily /home/skysigal/public_html/data/pages/it/ad/arangodb/howto/api/js/graphs_paths.txt Last modified: 2023/11/04 02:42by 127.0.0.1