azure - 为什么在生产中使用 CreateDatabaseIfNotExistsAsync 和其他类似的方法?

标签 azure azure-cosmosdb azure-cosmosdb-sqlapi

我正在讨论教程中的代码,如下所示:

DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

在我看来,如果您的应用程序启动并且找不到数据库(该数据库应该在应用程序重新启动/推出之间保持不变),则需要担心更大的问题,并且 CreateIfNotExists 毫无意义。

这是否是生产中推荐的模式?

最佳答案

It seems to me that if your app starts and it can't find a database (which should be persistent between app restarts/rollouts), there are bigger problems to worry about and the CreateIfNotExists is kind of meaningless.

Is this anyway a recommended pattern in production?

我认为这取决于您的需求。一般来说,使用CosmosClient.CreateDatabaseIfNotExistsAsync可以避免麻烦。但如果您需要检查,可以使用其他方法,例如 CosmosClient.CreateDatabaseAsyncCosmosClient.GetDatabase(String)CosmosClient.CreateDatabaseIfNotExistsAsync x 基本上是两者的组合。设计一些逻辑,如果不存在可以得到一些提示。

关于azure - 为什么在生产中使用 CreateDatabaseIfNotExistsAsync 和其他类似的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65402048/

相关文章:

azure - 存储帐户不存在,找不到 Function App 的引用

azure - 我需要多少个实例才能实现 Azure "Web Sites"的高可用性

python - CosmosDB Python获取多个项目

azure - 如何获取 CreateItemQuery 返回的项目的 ETag 值

Azure DTU 数据库 API

Azure APIM 根据两个不同的声明验证 JWT

azure-cosmosdb - Azure 搜索与 Azure DocumentDB

azure - 如何在不使用 GROUP BY 和 COUNT 的情况下在 cosmos db 中的嵌套数组中查找重复项

azure - 如何在 CosmosDB 上查询最近 30 天的数据?

azure-cosmosdb - 从 CosmosDB 中的不同分区查询文档的建议方法是什么?