We can use any programming languages like .NET, Java, Node.js, Python, PHP, etc to use Graph Database for both the SQL API and Gremlin API in our applications. We can use the SQL API to create and delete the graph databases and graphs, setting options on their throughput and partition keys. When you create a database by using the Gremlin.NET driver, it’s possible to insert and query your graph data more efficiently.
Create a Graph Database using Azure Portal
Step 1
Now sign-in to Azure Portal with your credential.
Step 2
On the Azure Portal menu, click on Create a Resource.
Step 3
Now click on Database --> Azure Cosmos DB
Step 4
On the Create Azure Cosmos DB Account page, enter the settings for the new Azure Cosmos DB account, including the location, database name, etc.
Step 5
Now, click on Review + Create Button
Step 6
After validating the setting, click on Create Button to create the Account.
Step 7
Once the deployment has been a success, click on the Go-To Resource Button.
Step 8
Now, click on the Data Explorer option in the left panel.
Step 9
Now click on the New Graph options to create the Database.
Step 10
Now provide the Database ID and Graph ID and then click on the OK button.
Step 11
Now, the Graph Database has been created.
Step 12
Now, click on the new vertex button to add new records. To insert new records in the Graph Database, we need to provide the data as the key-pair format. Also, we need to provide the name of the label of the Graph.
Step 13
Now, once we execute the Gremlin query in the Data Explorer, we can view the graph data both as Graph format & JSON data format.
Azure Cosmos DB supports the Gremlin traversal language. If you have previously written Gremlin queries to be used with a Neo4j or JanusGraph database, those queries will likely run unchanged against Cosmos DB. Cosmos DB also supports the JSON-based GraphSON format of data. The results from a Gremlin query are returned to the client in this format, providing further opportunities for interoperability.
Concept of vertices, labels, edges, and properties
If the domain that we are trying to model is made up of a heterogeneous collection of objects that are related to each other in many ways, then a graphing approach to storing and processing data is a good fit. Using a complex relational database as a starting point for a graph modeling exercise, you will see how relational data isn’t always the most efficient approach. For that purpose, we always need to remember to take a “Node First” approach to the model.
- Nodes - Distinct conceptual Identity
- Labels - Categories of Nodes
- Edges - The relationship between the nodes
- Properties - The metadata to be stored against nodes and edges.
Labels in a graph allow us to group vertices into sets—the benefit of applying labels is that you write a query to run against the reduced set of data instead of your whole graph.
Establish the relationship between different graph data
Now, in the Persons Graph (which we created earlier) we need to insert the below data as per the below table:
id
|
name
|
age
|
city
|
1
|
Eva
|
44
|
New Jersy
|
2
|
Albert
|
36
|
California
|
3
|
Veronica
|
32
|
Paris
|
4
|
Mohit Sharma
|
35
|
New Delhi
|
5
|
John
|
23
|
London
|
6
|
Dip
|
38
|
London
|
7
|
Robert
|
40
|
Paris
|
8
|
Eric
|
38
|
New Jersy
|
9
|
Smith
|
41
|
California
|
10
|
Stephen
|
25
|
New Delhi
|
Now, these all data are independent of each other. We need to establish a relationship between data. Suppose, we assume that the relationship between these data is Friendships. So, we need to establish the relationship between the above data as per below.
Eva is a Friend of Eric.