'Is it possible to create a new Gremlin Graph DB and Graph using c# code

I have a Azure Cosmos DB account with Gremlin API. I'm using Gremlin.Net to query the db.

var gremlinServer = new GremlinServer(hostname, port, enableSsl: true, username: "/dbs/" + database + "/colls/" + collectionName, password: authKey);

username parameter takes dbname and collection name.

Just wondering how to create a new graph db and a graph under the account using c# code.

Thanks



Solution 1:[1]

I searched the azure gremlin .Net source code , no such methods like creating database or graph could be found. There is an statement mentioned in above link?

This sample uses the open-source Gremlin.Net driver to connect to an Azure Cosmos DB Graph API account and run some basic Create, Read, Update, Delete Gremlin queries.

It seems that we could only execute gremlin queries, can't CRUD database itself.

I also searched Cosmos DB REST API, no such special api for CRUD cosmos db graph api. Only operations of database and collection could be found. So I tested it with below sample code with Document DB .Net SDK and it works for me.

client = new DocumentClient(new Uri(ConfigurationManager.AppSettings["endpoint"]), ConfigurationManager.AppSettings["authKey"]);
await client.CreateDatabaseAsync(new Database { Id = "db"});
await client.CreateDocumentCollectionAsync(
    UriFactory.CreateDatabaseUri(DatabaseId),
    new DocumentCollection
        {
           Id = "coll"
        },
    new RequestOptions { OfferThroughput = 400 });

I know it is strange(there is no collection in cosmos db graph api,it supposed to be graph) but it works for me.You could try it on your side.

enter image description here

Hope it helps you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jay Gong