【问题标题】:Google Datastore 1500 byte property limit for embedded entities嵌入式实体的 Google Datastore 1500 字节属性限制
【发布时间】:2017-06-05 16:06:42
【问题描述】:

根据:https://cloud.google.com/datastore/docs/concepts/entities#embedded_entity

在嵌入式实体上设置 excludeFromIndexes: true 应该会从索引中删除它及其属性,因此应该允许该嵌入式实体的属性大于 1500 字节。

我正在尝试编写一个嵌入式实体,它的某些属性超过 1500 字节,但出现错误:

“Error: The value of property “additionalAttributes” is longer than 1500 bytes. at /node_modules/grpc/src/node/src/client.js:434:17"

即使我在嵌入式实体上设置了excludeFromIndexes: true(并且我可以在云控制台中看到嵌入式实体在没有索引的情况下被正确添加)。

我发现有一个已知问题:https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1916。虽然我没有看到任何修复或解决方法

有关导致此问题的原因以及如何修复/解决方法的任何建议?

【问题讨论】:

    标签: google-cloud-datastore


    【解决方案1】:

    最简单的方法是添加 @Unindexed 注释,这将删除该属性的索引并允许您插入超过 1500 字节的字符串属性。

    【讨论】:

      【解决方案2】:

      我的问题/问题确实是这个: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1916

      答案/解决方案是通过此 PR https://github.com/GoogleCloudPlatform/google-cloud-node/pull/2497 的固定版本

      【讨论】:

        【解决方案3】:

        我正在使用此修复程序以递归方式在所有属性上设置 {excludeFromIndexes: false},但其中三个除外。在将属性发送到数据存储区之前调用 entity.entityToEntityProto 方法,但前提是您的 entity.data 是一个对象(也可以传递一个数组)。

        您可以将此脚本包含在节点中的任何位置,最好是在启动 Datastore 之前。它将覆盖 entity.entityToEntityProto 方法。

        const INCLUDE_ATTRIBUTES = ['_index','_audit','_unique'];
        
        function entitySetIndexes(properties, path){
            for(let key in properties){
                let keypath = (path ? path+'.' : '') + key
                    , prop = properties[key];
        
                if(prop.entityValue)
                    entitySetIndexes(prop.entityValue.properties, keypath);
                else if(prop.arrayValue)
                    prop.arrayValue.values.forEach(item=>{
                        if(item.entityValue)
                            entitySetIndexes(item.entityValue.properties, keypath)
                    });
        
                // excludeFromIndex cannot be set on arrays, they're always indexed
                if(!prop.arrayValue)
                    prop.excludeFromIndexes = INCLUDE_ATTRIBUTES.indexOf(keypath) === -1;
            }
        }
        
        const entity = require('@google-cloud/datastore/src/entity.js')
            , entityToEntityProto = entity.entityToEntityProto;
        entity.entityToEntityProto = function(entityObject){
            entityObject = entityToEntityProto(entityObject);
            entitySetIndexes(entityObject.properties);
            return entityObject;
        }
        

        因此,只需确保使用 {data:{attribute:'value'}, key:...} 保存实体即可。如果要索引深层属性,请指定它们以点分隔,忽略数组。 我正在使用@google-cloud/datastore v1.1.0 中的脚本。

        【讨论】:

          【解决方案4】:

          解决方法是至少为那些需要支持超过 1500 字节的属性设置excludeFromIndexes=true。嵌入式实体的 JSON 应如下所示。请注意我们明确设置excludeFromIndexestext 属性。

          {
            "properties": {
              "date": {
                "timestampValue": "2017-06-05T18:53:23.106Z"
              },
              "text": {
                "stringValue": "long text that exceeds 1500 bytes",
                "excludeFromIndexes": true
              }
            }
          }
          

          【讨论】:

          • 我的问题是嵌入式属性的大属性,afaik 你不能将excludeFromIndexes: true 放在嵌入式实体的属性上(或者如果可以,你会怎么做?)跨度>
          • 我的例子确实是来自 GCD 控制台的嵌入式实体。我使用了非常简单的 Java API 来排除任何属性(顶级或嵌套)。对 NodeJS 不太熟悉。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-07-25
          • 1970-01-01
          • 1970-01-01
          • 2015-05-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多