Cosmos DB 模拟器:"'analyticalStorageTtl' is not a valid property in the current payload"设置分析存储时间到活在秒



在Emulator(v2.11.5.0(中使用.NET Standard SDK并尝试在ContainerProperties对象上设置AnalyticalStoreTimeToLiveInSeconds来创建容器时,会引发以下异常:

Microsoft.Azure.Cosmos.CosmosException: 'Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: c4b8a5d2-29e3-4720-918c-123eb10da0a4; Reason: (Message: {"Errors":["The input content is invalid - 'analyticalStorageTtl' is not a valid property in the current payload."]}

ActivityId: c4b8a5d2-29e3-4720-918c-123eb10da0a4, Request URI: /apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: , SDK: Microsoft.Azure.Documents.Common/2.11.0, Please see CosmosDiagnostics, Windows/10.0.18362 cosmos-netstandard-sdk/3.11.4);'

使用云托管的CosmosDB时没有错误,只有在使用模拟器时才有错误。互联网搜索对此毫无结果,有人知道吗?

要复制的代码

程序.cs:

using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
namespace ConsoleApp2
{
public class Program
{
public static async Task Main(string[] args)
{
const string databaseName = "TestDatabase";
const string containerName = "TestContainer";
var accountEndpoint = "https://localhost:8081";
var authKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
var cosmosClient = new CosmosClient(accountEndpoint, authKey);
await cosmosClient.CreateDatabaseIfNotExistsAsync(databaseName, 400);
var database = cosmosClient.GetDatabase(databaseName);
await database.CreateContainerAsync(new ContainerProperties
{
Id = containerName,
PartitionKeyPath = "/id",
AnalyticalStoreTimeToLiveInSeconds = 0 // Removing this line makes the exception go away
});
}
}
}

控制台App2.csproj

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.12.0" />
</ItemGroup>
</Project>

根据Mark Brown的评论,Azure Cosmos DB Emulator不支持Analytical Store,因此不允许使用该设置创建容器,因此发生此错误。

此外,微软并没有真正打算将SDK用于创建/更新DevOps场景的容器,因此也不打算在这里改变模拟器的行为。

对于我们的项目,开发人员使用模拟器在他们的机器上进行本地测试,作为短期解决方案,我们使用应用程序设置来控制这一点。

从长远来看,我们将把容器创建作为部署管道的一部分,并使用脚本进行处理。

最新更新