标签: azure-cosmosdb

CosmosDB 独特关键问题

我面临着 CosmosDB 唯一键约束的问题。设置唯一键后,我可以插入具有相同分区键的重复文档。请帮助我理解我是否做错了什么。

创建一个容器,其唯一键为“/name”,分区键为“/partition”

我能够使用 azure 门户数据资源管理器工具在同一分区键下创建重复名称

文件1

{
"id": "1",
"partition": "p1",
"name": "Balaji",
"age": 20,
"_rid": "Y48OAI3aptUBAAAAAAAAAA==",
"_self": "dbs/Y48OAA==/colls/Y48OAI3aptU=/docs/Y48OAI3aptUBAAAAAAAAAA==/",
"_etag": "\"8e016bfd-0000-0700-0000-5e96d8a50000\"",
"_attachments": "attachments/",
"_ts": 1586944165
}
Run Code Online (Sandbox Code Playgroud)

文件2

{
"id": "2",
"partition": "p1",
"name": "Balaji",
"age": 20,
"_rid": "Y48OAI3aptUCAAAAAAAAAA==",
"_self": "dbs/Y48OAA==/colls/Y48OAI3aptU=/docs/Y48OAI3aptUCAAAAAAAAAA==/",
"_etag": "\"8f017400-0000-0700-0000-5e96d8d60000\"",
"_attachments": "attachments/",
"_ts": 1586944214
}
Run Code Online (Sandbox Code Playgroud)

提前谢谢!

unique-key azure-cosmosdb

2
推荐指数
1
解决办法
1680
查看次数

Azure Cosmos db Gremlin elementMap()

我试图在 cosmos db 中创建一个 gremlin 查询,其中所有顶点的属性都被展平。

我取得的最好成就是使用“valueMap”

询问

g.V('12345').valueMap(true))
Run Code Online (Sandbox Code Playgroud)

结果

{
   "id": "12345",
   "label": "product",
   "name": [
     "product name"
   ],
   "description": [
     "productdescription"
   ],
}
Run Code Online (Sandbox Code Playgroud)

我想要实现的目标

{
   "id": "12345",
   "label": "product",
   "name": "product name",
   "description": "productdescription"
}
Run Code Online (Sandbox Code Playgroud)

看起来 elementMap 是正确的方法,但 Cosmos Db 似乎不支持它。

是否有不支持此功能的原因或是否存在类似的解决方案?

azure graph-databases gremlin azure-cosmosdb azure-cosmosdb-gremlinapi

2
推荐指数
1
解决办法
616
查看次数

Cosmos DB:请求失败,因为客户端无法与跨 1 个区域的 1 个端点建立连接

HTTP 触发器 Azure 函数的应用程序见解中记录了以下异常。

请求失败,因为客户端无法与跨 1 个区域的 1 个端点建立连接。尝试请求期间客户端 CPU 过载

"outerId":"0","message":"响应状态码不表示成功:ServiceUnavailable (503); Substatus: 0; ActivityId: 35d16569-41da-42ed-bc5c-8f9a5c49078e; 原因:(请求失败,因为客户端无法跨 1 个区域建立与 1 个终结点的连接。客户端 CPU 在尝试请求期间过载。\r\nActivityId: 35d16569-41da-42ed-bc5c-8f9a5c49078e,请参阅 CosmosDiagnostics、Windows/10.0.14393 cosmos-netstandard -sdk/3.9.0);","parsedStack":[{"程序集":"Microsoft.Azure.Cosmos.Client, Version=3.9.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"Microsoft .Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode","级别":0,"行":0},{"程序集":"Microsoft.Azure.Cosmos.Client,版本= 3.9.1.0,文化=中性,PublicKeyToken = 31bf3856ad364e35 ","方法":"Microsoft.Azure.Cosmos.ReadFeedResponse 1.CreateResponse","level":1,"line":0},{"assembly":"Microsoft.Azure.Cosmos.Client, Version=3.9.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"Microsoft.Azure.Cosmos.FeedIteratorCore1+d__6.MoveNext","级别":2,"行":0},{"程序集":"System.Private.CoreLib,版本=4.0。 0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e","方法":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","级别":3,"行":0},{"程序集":"System.Private。 CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e","方法":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","级别":4,"行":0},{"程序集" :“FleetHub.Notifications.Domain,版本= 1.0.0.0,文化=中性,PublicKeyToken = null”,“方法”:“FleetHub.Notifications.Domain.Repositories.CosmosDBRepository 1+<GetItemsAsync>d__10.MoveNext","level":5,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":6,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","level":7,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":8,"line":0},{"assembly":"FleetHub.Notifications.Queries, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","method":"FleetHub.Notifications.Queries.Handlers.RetrieveNotificationQueryHandler+<GetNotifications>d__4.MoveNext","level":9,"line":41,"fileName":"D:\\a\\144\\s\\FleetHub.Notifications.Queries\\Handlers\\RetrieveNotificationQueryHandler.cs"},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":10,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","level":11,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":12,"line":0},{"assembly":"FleetHub.Notifications.Queries, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","method":"FleetHub.Notifications.Queries.Handlers.RetrieveNotificationQueryHandler+<GetNotificationSummary>d__5.MoveNext","level":13,"line":54,"fileName":"D:\\a\\144\\s\\FleetHub.Notifications.Queries\\Handlers\\RetrieveNotificationQueryHandler.cs"},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":14,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","level":15,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, …

azure-functions azure-cosmosdb

2
推荐指数
1
解决办法
6659
查看次数

有没有办法将 Azure Cosmos DB 吞吐量设置为低于 400 RU/s?

我尝试将 Azure Cosmos DB 设置中的 Cassandra 表的吞吐量设置为低于 400,但它似乎不起作用。保存按钮变为非活动状态,不允许这样做。

我正在运行一个永远不会产生如此高吞吐量的测试服务器。是否可以将最小吞吐量设置为小于 400 RU/s?

azure azure-cosmosdb azure-cosmosdb-cassandra-api

2
推荐指数
1
解决办法
573
查看次数

查询以获取另一个引用的所有 Cosmos DB 文档

假设我有以下 Cosmos DB 容器,其中包含可能的文档类型分区:

{
  "id": <string>,
  "partitionKey": <string>, // Always "item"
  "name": <string>
}
Run Code Online (Sandbox Code Playgroud)
{
  "id": <string>,
  "partitionKey": <string>, // Always "group"
  "items": <array[string]>  // Always an array of ids for items in the "item" partition
}
Run Code Online (Sandbox Code Playgroud)

我有一个“组”文档的 ID,但我没有该文档本身。我想做的是执行一个查询,为我提供“组”文档引用的所有“项目”文档。

我知道我可以执行两个查询:1)检索“group”文档,2)在“item”分区上使用 IN 子句执行查询。

由于除了获取 id 列表之外,我不关心“组”文档,因此是否可以构造一个查询来仅使用“组”文档 id 来获取我想要的所有“项目”文档?

azure azure-cosmosdb azure-cosmosdb-sqlapi

2
推荐指数
1
解决办法
1669
查看次数

Cosmos:从 c# / .Net 容器中的分区中获取所有项目 #CosmosClient

我创建了一个容器来存储客户的用户信息。分区键是 customerId。我想读取 customerId = X 的逻辑分区中的所有项目,这应该返回 customerId = X 的所有用户记录。.NET SDK 中的 CosmosClient 是否提供此类 API?

例子 :

class User
{
      string customerId,
      string userId,
      string userName
}
Run Code Online (Sandbox Code Playgroud)

azure-cosmosdb

2
推荐指数
1
解决办法
5418
查看次数

无法为 cosmos db 分配 Azure 角色

我正在尝试为一个身份分配一个角色来读取/写入cosmos db。我运行这个命令:

az role assignment create \
--assignee <sp_object_id> \
--role "00000000-0000-0000-0000-000000000002" \
--scope "/subscriptions/<subscriptionId>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/databaseAccounts/<cosmos-db-name>"
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

The specified role definition with ID '00000000000000000000000000000002' does not exist.
Run Code Online (Sandbox Code Playgroud)

我尝试过使用角色名称,但无济于事。我已经尝试过 GUI,但这个角色在任何地方都看不到。

我该如何分配这个角色?

azure azure-cli azure-cosmosdb

2
推荐指数
1
解决办法
3343
查看次数

Cosmos DB 返回 404

我正在成功连接我的新 Cosmos DB。

private async Task InitialiseDb()
        {
            client = new CosmosClient(cosmosUrl, cosmosKey);
            database = await client.CreateDatabaseIfNotExistsAsync(databaseName);
            container = await database.CreateContainerIfNotExistsAsync("MyContainer", "/id");
        }
Run Code Online (Sandbox Code Playgroud)

然后,我设法将一个项目填充到我的 Cosmos 实例中。

 var response = await container.CreateItemAsync(myDocument);
Run Code Online (Sandbox Code Playgroud)

当登录到 Azure 并查看我的项目时,我看到了该项目。所以就保存下来了。

现在我试图取回该项目,但收到有关 的错误not found

Microsoft.Azure.Cosmos.CosmosException :响应状态代码不指示成功:NotFound (404);子状态:0;活动ID:e90da49c-510e-4940-a888-9531427a3810;原因:(错误:[“未找到资源。了解更多信息:https://aka.ms/cosmosdb-tsg-not-found”]);

我获取该物品的方法非常简单:

public async Task<MyDto> GetRecord(Guid myId)
        {
            var data = await container.ReadItemAsync<FlightDoc>(myId.ToString(), new PartitionKey("id"));
            return new MyDto
            {
                Id = Guid.Parse(data.Resource.id)
            };
            
        }
Run Code Online (Sandbox Code Playgroud)

我认为我误解了分区及其工作原理。有什么明显不对的地方吗?这是我的数据浏览器的部分屏幕截图:

在此输入图像描述

我正在传递上面 ID 中显示的 ID。

编辑:更好地解释数据。这次飞行,收集了很多样品。一个航班有很多样本...每个样本都有一个 ID。但我正在努力带回 Flgith 和样本。

在此输入图像描述

c# azure azure-cosmosdb

2
推荐指数
1
解决办法
3787
查看次数

返回 CosmosDB 中的部分文档

我有一个包含许多字段的大型文档,我只想从对象返回 1-2 个字段以保持吞吐量。这在 cosmosDB 中可能吗?还是我需要每次都返回整个对象?

azure-cosmosdb

2
推荐指数
1
解决办法
719
查看次数

更新 Cosmos DB TTL 容器设置是否会对旧项目产生影响?

我用此代码更新了我的 cosmos db 容器

var containerResponse = await _cosmosContainer.ReadContainerAsync();
            var containerProperties = containerResponse.Resource;
            if (containerProperties.DefaultTimeToLive == null)
            {
                containerProperties.DefaultTimeToLive = 60 * 60 * 24 * 180; // set 180 days default TTL 
                await _cosmosContainer.ReplaceContainerAsync(containerProperties);
            }
Run Code Online (Sandbox Code Playgroud)

更新 Cosmos DB TTL 容器设置是否会对旧项目产生影响?

.net c# azure ttl azure-cosmosdb

2
推荐指数
1
解决办法
671
查看次数