Search code examples
c#azure-cosmosdbgremlin

How can I create a Graph in CosmosDB from Code


If I want to connect to CosmosDB which is created with Gemlin API is works fine with Gremlin.Net

But the Gremlin.NET API is designed to handle on Graph. I think because the Neo4j and other Graph databases can handle one graph in one time. And I want a new a Graph in CosmosDB I can create it from Azure portal.

But How can I create a new Graph from Code? Of course when I connect to same CosmosDB instance with DocumentDB API, then I Can create a new Collection which is Graph in Cosmos. But this is not safe for some reason:

  1. Not recommended to Connect to Cosmos with Different API-s.
  2. When I create a Graph from Azure Portal, maybe there is some other initialization code is running, other than just create an empty collection

Is there a safe way to create Graph In CosmosDB from Code?


Solution

  • The initialization code only runs when you create a Cosmos DB account with Gremlin API. The initialization code creates a Gremlin webseocket server endpoint which is specific to Gremlin API.

    After that, creating a Graph is equivalent to creating a collection/container using the Document DB API.

    Please send us an email at [email protected].

    Jayanta