zino
zino

Reputation: 1472

Storing hierarchical data in Google Datastore

I have data in the following structure:

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

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

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

I want to put/get this in Google Datastore. What is the best way to store this?

Should I be using entity groups?

Requirements:

This 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?) mentions they should only be used for transactions, which I do not need.

Im using this library (which I do not think supports ReferenceProperty?). http://github.com/GoogleCloudPlatform/gcloud-ruby.git

Upvotes: 0

Views: 611

Answers (2)

Brent Washburne
Brent Washburne

Reputation: 13158

In my experience, the more entities you request the slower (less performant) it becomes. Making lots of entities with small bits of data is not efficient. Instead, store the whole hierarchy as a JsonProperty and use code to walk through it.

If KeyE is just a string, then add a property KeyE = StringProperty(indexed=True) so you can query against it.

Upvotes: 0

Dmytro Sadovnychyi
Dmytro Sadovnychyi

Reputation: 6201

If you want to be able to query by the hierarchy (keyA->keyB->keyC) -- use ancestors, or just a key which will look like this to avoid entity group limits. If you want to be able to query an entity which contains provided key -- make a computed property where you will store a flat list of keys stored inside. And store the original hierarchy in the JsonProeprty for example.

Upvotes: 2

Related Questions