0

I am trying to get metadata information of my Cosmos Graph Database. There are a number of Graphs created in this database and I want to list those Graph names.

In the Gremlin API, we have support to connect to any Graph DB container and then we can submit the query as I mentioned in the below code sample. But here we need a {collection} that is our GraphName as well. So somehow we are bound to a particular graph here.

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

                using (var gremlinClient = new GremlinClient(gremlinServer, new GraphSON2Reader(), new GraphSON2Writer(), GremlinClient.GraphSON2MimeType))
                {
                    gremlinClient.SubmitAsync(query);
                }

Is there any way so that we can connect to GraphDB only and get some metadata information ? Such as, in my case, list of available Graphs.

chandler
  • 3
  • 1

1 Answers1

0

It looks like the Gremlin Client is implemented at a Collection level (i.e. graph) so it won't be possible to enumerate Graphs from one account / database using the gremlin connection.

You can always use the CosmosDB SDK to connect to the account and enumerate the databases/collections and then use the Gremlin Clients to connect to each of them separately.

Install-Package Microsoft.Azure.Cosmos

using (var client = new CosmosClient(endpoint, authKey))
{
    var dbIterator = client.GetDatabaseQueryIterator<DatabaseProperties>();
    while(dbIterator.HasMoreResults)
    {
        foreach (var database in await dbIterator.ReadNextAsync())
        {
            var containerIterator = database.GetContainerQueryIterator<ContainerProperties>();
            while (containerIterator.HasMoreResults)
            {
                 foreach (var container in await containerIterator.ReadNextAsync())
                 {
                      Console.WriteLine($"{database.Id} - {container.Id}");
                 }
            }
        }
    }
}
AlexDrenea
  • 7,981
  • 1
  • 32
  • 49