2017-07-21 31 views
0

我剛開始接觸GCP和文檔有點混亂(有不少,但也有很多方法可以做到一單一的東西)。GCP數據存儲:不能存儲在單一陣列型性能指標值類型不同

我有一個實體Array類型的屬性。我可以stringValue型KV對添加多個到單個索引數組中,像這樣:

"values": [ 
    { 
     "stringValue": "google.com", 
     "stringValue": "k" 
    }, 
    { 
     "stringValue": "facebook.com" 
    } 
    ] 

沒有GCP了結問題,但如果我試圖改變這

"values": [ 
    { 
     "stringValue": "google.com", 
     "timestampValue": "xxxxxxxxxx" 
    }, 
    { 
     "stringValue": "facebook.com" 
    } 
    ] 

它贏得」讓我保存。我絕對必須爲此使用嵌套實體嗎?在陣列型

回答

1

元素可以是任何支持的類型的,不同之處另一個陣列。這意味着,數組類型可以包含字符串,整型,浮點型,時間戳,空值,嵌入式實體等元素。

在GCD控制檯中格式正確的數組看起來像下圖所示。這個數組有兩個String元素,一個Integer和一個時間戳。

{ 
    "values": [ 
    { 
     "stringValue": "propertyValue1" 
    }, 
    { 
     "stringValue": "propertyValue2" 
    }, 
    { 
     "integerValue": "300" 
    }, 
    { 
     "timestampValue": "2014-10-02T15:01:23.045123Z" 
    } 
    ] 
} 

如果您需要嵌入實體存儲在數組中,它應該是這樣的:

{ 
    "values": [ 
    { 
     "entityValue": { 
     "properties": { 
      "countryCode": { 
      "stringValue": "91" 
      }, 
      "subscriberNumber": { 
      "stringValue": "2722 5858" 
      }, 
      "areaCode": { 
      "stringValue": "40" 
      } 
     } 
     } 
    }, 
    { 
     "entityValue": { 
     "properties": { 
      "subscriberNumber": { 
      "stringValue": "6666 0000" 
      }, 
      "areaCode": { 
      "stringValue": "80" 
      }, 
      "countryCode": { 
      "stringValue": "91" 
      } 
     } 
     } 
    } 
    ] 
} 
+0

謝謝!當我有時間嘗試一下時,我會將其標記爲已接受! – kidCoder