首页 > 解决方案 > 是否可以使用 c# 代码创建新的 Gremlin Graph DB 和 Graph

问题描述

我有一个使用 Gremlin API 的 Azure Cosmos DB 帐户。我正在使用 Gremlin.Net 查询数据库。

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

username 参数采用 dbname 和集合名称。

只是想知道如何使用 c# 代码在帐户下创建一个新的图形数据库和一个图形。

谢谢

标签: c#azureazure-cosmosdbgremlin

解决方案


我搜索了azure gremlin .Net源代码,找不到像创建数据库或图形这样的方法。上面的链接里有一个说法:</p>

此示例使用开源 Gremlin.Net 驱动程序连接到 Azure Cosmos DB Graph API 帐户并运行一些基本的创建、读取、更新、删除 Gremlin 查询。

似乎我们只能执行 gremlin 查询,不能 CRUD 数据库本身。

我还搜索了Cosmos DB REST API,没有针对 CRUD cosmos db graph api 的特殊 api。只能找到数据库和集合的操作。因此,我使用Document DB .Net SDK使用以下示例代码对其进行了测试,它对我有用。

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 });

我知道这很奇怪(cosmos db graph api 中没有集合,它应该是图形)但它对我有用。你可以在你身边尝试。

在此处输入图像描述

希望它可以帮助你。


推荐阅读