在 Google 数据存储中存储分层数据

Storing hierarchical data in Google Datastore

我有以下结构的数据:

{
  "id": "1",
  "title": "A Title",
  "description": "A description.",

  "listOfStrings": ["one", "two", "three"]

  "keyA": {
    "keyB": " ",
    "keyC": " ",
    "keyD": {
      "keyE": " ",
      "KeyF": " "
    }
  } 
}

我想 put/get 在 Google 数据存储中。最好的存储方式是什么?

我应该使用实体组吗?

要求:

这个 link (Storing hierarchical data in Google App Engine Datastore?) mentions using entity groups for hierarchical data, but this link (How to get all the descendants of a given instance of a model in google app engine?) 提到它们应该只用于交易,我不需要。

我正在使用这个库(我认为它不支持 ReferenceProperty?)。 http://github.com/GoogleCloudPlatform/gcloud-ruby.git

如果您希望能够按层次结构 (keyA->keyB->keyC) 进行查询 -- 使用祖先,或者只使用看起来像这样的键以避免实体组限制。如果您希望能够查询包含提供的键的实体——创建一个计算的 属性 ,您将在其中存储存储在其中的键的平面列表。并将原始层次结构存储在 JsonProeprty 中,例如。

根据我的经验,您请求的实体越多,它就会变得越慢(性能越差)。使用少量数据创建大量实体效率不高。相反,将整个层次结构存储为 JsonProperty 并使用代码遍历它。

如果 KeyE 只是一个字符串,则添加一个 属性 KeyE = StringProperty(indexed=True) 以便您可以对其进行查询。