Performing CRUD operations in Graph DB

As discussed in Chapter 3, Cosmos DB Multi-model Databases, a graph data model is a structure that's comprised of vertices and edges. Both vertices and edges can have a set number of properties:

  • Vertices represent discrete objects, such as a person, a place, or an event.
  • Edges represent relationships between vertices. For example, a person might know another person, be involved in an event, and recently have been at a location.
  • Properties denote details about the vertices and edges. Azure Cosmos DB supports the property graph model.

Let's create a new database first:

  1. Click on New Database and choose the Gremlin as API. Refer to the following screenshot for reference:
  1. Now, create a new graph database and Graph Id. Refer to the following screenshot for reference:
  1. Now, you need to generate the keys to connect it via any programming interface. Go to Settings | Keys and click on the primary and secondary keys to generate it. Refer to the following screenshot for reference:

We can use these keys to connect to your Graph database using the code.

Now, coming to the CRUD part, we can create new vertices and edges using the Azure portal as well as code too. We have covered the Azure portal in Chapter 3, Cosmos DB Multi-model Database, as well.

Once you have created some vertexes and edges and added some properties to them, you can perform the query on the graph.

One of the simplest ways is to do so is via the Azure terminal.

  1. Run this query to return the vertices of the graph:
g.V().count() 

You can, in fact, delete the vertices from the graph and edit them dynamically using the portal UI.

Graph is a very vast topic and you can do lots more in it.

The following is a reference link where you can read further details about graph:
https://docs.microsoft.com/en-us/azure/cosmos-db/gremlin-support

Now, let's see how to perform the CRUD operation in the Table database API.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.246.247