On this page

Matching patterns

Match patterns (querying data)

In BangDB we follow a similar to Cypher format for matching data or preferably querying data. However, BangDB doesn’t use ‘MATCH’ keyword/clause for the same instead it uses something like <var_name>=> before the query

For ex; S=>

To find the data we’ve created so far, we can start looking for all nodes labelled with the Movie label.

S=>(Movie:*)

{
   "num_items":2,
   "nodes":[
      "{\"released\":1994,\"label\":\"Movie\",\"name\":\"Forrest Gump\",\"_pk\":\"889565392:607499282203478465\",\"_v\":1}",
      "{\"title\":\"The Matrix\",\"released\":1997,\"label\":\"Movie\",\"name\":\"Matrix\",\"_pk\":\"889565392:7731255011213178614\",\"_v\":1}"
   ]
}
Note: the _pk and _v is added by the db for its housekeeping reasons

We can also look for a specific Movie, like “Forrest Gump”

S=>(@p "Person:Tom Hanks")-[@r ACTED_IN]->(@m Movie:*); RETURN m.name AS Title, r.roles AS Role

+---------------+-----------------------+
|  Role         |      Title            |
+---------------+-----------------------+
| ["Forrest"]   |      Forrest Gump     |
+---------------+-----------------------+

We could also see in json format by setting output as JSON

{
   "rows":[
      {
         "Title":"Forrest Gump",
         "Role":"[\"Forrest\"]"
      }
   ]
}

Let’s add another film where Tom Hanks acted in. Since Tom Hanks already exists hence, we may just use the name

CREATE (Person:"Tom Hanks")-[ACTED_IN {"roles":["Zachry"]}]->(Movie:"Cloud Atlas" {"released":2012})

{
   "errcode":0,
   "msg":[
      "success"
   ]
}

Now it’s a good time to create another graph and do following.

CREATE GRAPH ex_graph
USE GRAPH ex_graph
CREATE (Movie:matrix {"title":"The Matrix", "released":1997})
CREATE (Movie:cloudAtlas {"title":"Cloud Atlas", "released":2012})
CREATE (Movie:forrestGump {"title":"Forrest Gump", "released":1994})
CREATE (Person:keanu {"fullname":"Keanu Reeves", "born":1964})
CREATE (Person:robert {"fullname":"Robert Zemeckis", "born":1951})
CREATE (Person:tom {"fullname":"Tom Hanks", "born":1956})
CREATE (Person:tom)-[ACTED_IN {"roles":["Forrest"]}]->(Movie:forrestGump)
CREATE (Person:tom)-[ACTED_IN {"roles":["Zachry"]}]->(Movie:cloudAtlas)
CREATE (Person:robert)-[DIRECTED]->(Movie:forrestGump)
Was this article helpful to you? Yes No