2

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

1 Answer 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.