【问题标题】:Azure Cosmos-db Renaming documents propertiesAzure Cosmos-db 重命名文档属性
【发布时间】:2019-10-15 15:14:36
【问题描述】:

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

例子:

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

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

【问题讨论】:

    标签: c# azure azure-cosmosdb


    【解决方案1】:

    正如您在问题中提到的,您可以使用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.
                    }
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 1970-01-01
      • 2018-04-13
      • 2018-06-20
      • 1970-01-01
      相关资源
      最近更新 更多