Examples
Quick Start - Social Graph
Build a simple social network with follows relationships using CogDB.
Learn how to create a basic social graph and query relationships.
Creating the Graph
from cog.torque import Graph
g = Graph("social")
g.put("alice", "follows", "bob")
g.put("bob", "follows", "charlie")
g.put("alice", "follows", "charlie")Query Outgoing Edges
Find who Alice follows using out():
# Who does Alice follow?
g.v("alice").out("follows").all()
# {'result': [{'id': 'bob'}, {'id': 'charlie'}]}Query Incoming Edges
Find who follows Charlie using inc():
# Who follows Charlie?
g.v("charlie").inc("follows").all()
# {'result': [{'id': 'alice'}, {'id': 'bob'}]}Explanation
g.v("alice")- Start at the vertex "alice".out("follows")- Follow outgoing "follows" edges.inc("follows")- Follow incoming "follows" edges.all()- Return all matching results