c# - 是否可以使用 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# 代码在帐户下创建一个新的图形数据库和一个图形。
谢谢
解决方案
我搜索了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 中没有集合,它应该是图形)但它对我有用。你可以在你身边尝试。
希望它可以帮助你。
推荐阅读
- powerbi - 在 Power BI 中计算迄今为止的平均年份
- http - 如果 Elm 中的 Http.get 请求收到与预期不同类型的响应,会发生什么?
- angular - 如何显示 * 而不是数字?
- react-native - React Native 动态 FlatList
- angular - Angular 将所有 /(反斜杠)替换为 %5C
- flutter - 无法在颤振启动画面/首屏中渲染图像(仅限 iOS)
- javascript - App Maker 的时间选择器和自动完成功能
- c# - 在 C# 中传递结构定义
- spring - Spring Boot Camel Route - 从休息端点获取数据
- windows - Kiwi Tcms Windows 无docker安装配置