Azure / azure-cosmos-dotnet-v2

Contains samples and utilities relating to the Azure Cosmos DB .NET SDK
MIT License
577 stars 838 forks source link

Is there way to create Graph database and container using Gremlin.Net and run queries on it #779

Open pavitrag123 opened 4 years ago

pavitrag123 commented 4 years ago

We have requirement to create graph database dynamically and run queries on it.

Tried using Microsoft.Azure.Graphs SDK but it is causing version conflict issues with other azure sdks in solution and also read it is going to be deprecated. Is there a way we can achieve it using Gremlin.Net or any other SDKs?

Any help would be much appreciated. Thanks in advance

olivertowers commented 4 years ago

A graph on your Gremlin API Azure Cosmos account is the same as a container/collection, so you can use the Azure Cosmos DB SDKs to create a graph on a database via create container/collection request.

We recommend using that latest version of azure-cosmos-dotnet-v3

Using this SDK you can create a on your database like so:

            // Set throughput to the minimum value of 400 RU/s
            ContainerResponse simpleContainer = await database.CreateContainerIfNotExistsAsync(
                id: containerId,
                partitionKeyPath: partitionKey,
                throughput: 400);

Full sample is available here.

If you are unable to upgrade to v3 sdk, you can use v2 sdk to do the equivalent by creating DocumentCollection:

            DocumentCollection partitionedCollection = await client.CreateDocumentCollectionIfNotExistsAsync(
                UriFactory.CreateDatabaseUri(DatabaseName),
                collectionDefinition,
                new RequestOptions { OfferThroughput = 10100 });

See full sample here.

pavitrag123 commented 4 years ago

Thank you for the response Oliver. So, I will use Microsoft Azure Cosmos DB .NET SDK to create graph database/container and Gremlin.Net to query the database