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?
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.