it:ad:arangodb:howto:api:js:graphs_paths

IT:ArangoDB:HowTo:API/JS/Graphs/Paths

//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());
}

//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());
}

//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());
}

Who knows X

//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());
}

  • /home/skysigal/public_html/data/pages/it/ad/arangodb/howto/api/js/graphs_paths.txt
  • Last modified: 2023/11/04 02:42
  • by 127.0.0.1