c# - Azure Cosmos-db 重命名文档属性

标签 c# azure azure-cosmosdb

我有一个很大的cosmos-db集合,我想重命名这个集合的一些属性,我发现我可以实现C#应用程序,它在集合文档上循环,并每个文档替换它们,但是这个解决方案将根据集合大小需要很长时间。 Azure Portal(函数或存储过程)或 SDK 上是否有其他解决方案,可以让我们用更少的时间实现相同的功能?

示例:

旧文档 { 代码, C 名称, C地址 }

我想将属性重命名为 { 客户代码, 顾客姓名, 客户地址 }

最佳答案

正如您在问题中提到的,您可以使用 Stored Procedure要做到这一点。您可以按照示例代码 here

  function rename(document, update) {
        var fields, i, existingFieldName, newFieldName;

        if (update.$rename) {
            fields = Object.keys(update.$rename);
            for (i = 0; i < fields.length; i++) {
                existingFieldName = fields[i];
                newFieldName = update.$rename[fields[i]];

                if (existingFieldName == newFieldName) {
                    throw new Error("Bad $rename parameter: The new field name must differ from the existing field name.")
                } else if (document[existingFieldName]) {
                    // If the field exists, set/overwrite the new field name and unset the existing field name.
                    document[newFieldName] = document[existingFieldName];
                    delete document[existingFieldName];
                } else {
                    // Otherwise this is a noop.
                }
            }
        }
    }

关于c# - Azure Cosmos-db 重命名文档属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58397908/

相关文章:

azure - 如何从同一 ASE 内的 Web 应用调用 Azure ILB ASE 内的 API

Azure 云服务上的 WCF 与 Azure 网站客户端

docker - 是否可以使用 Table API 选项在 docker-compose 中运行 Cosmos DB

azure - Terraform - 将 for_each 与元组内的字符串列表一起使用

c#.net ListView - 从不同的表中提取不同的信息

c# - 如何从 Powershell 调用 GetInstance

c# - 用户代码未处理 CryptographicException

c# - Xamarin.Forms Shared不在Android View 中显示图像,但在iOS View 中显示图像

c# - 是否可以在仅具有公共(public)链接的容器中列出 Azure Blob?

sql - 当 JSON 包含 sql 关键字时无法获取结果