Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GAE Storing Key vs StringID

Are there advantages to storing Keys over String in Google App Engine datastore.

For example:

class Model(ndb.Model):
    user_key = ndb.KeyProperty()

VS

class Model(ndb.Model):
    user_id = ndb.StringProperty()
  • Why would you want to store a Key instead of the StringID? Is it only for convenience?
  • Which uses less storage space?
  • Which is faster to query?
like image 682
Kyle Finley Avatar asked Feb 11 '12 03:02

Kyle Finley


1 Answers

If you're using entity groups (ancestors), the KeyProperty will support that. When storing the id, unless the model who's id you're storing is the entity group root, you'll need to store enough info reconstruct the full key.

The KeyProperty will take more space, since it is storing additional data, but it may be more convenient to use when retrieving the other entity. Query speed should be comparable.

like image 122
Robert Kluin Avatar answered Oct 11 '22 17:10

Robert Kluin