Search code examples
pythongoogle-cloud-platformgoogle-cloud-datastoreapp-engine-ndb

Google NDB Model syntax


I have an example line of code for google ndb model (datastore)

V=model.Video.query(model.Video.key==key).get()

Assuming that the 'key' has a value, is the instantiation lines below feasible/valid or syntactically correct ?

+ (Video)key.get()
+ V = model.Video(key)

Not sure if they would work. Thanks for your inputs

https://cloud.google.com/appengine/docs/standard/python/ndb/creating-entities


Solution

  • If you have the (valid) entity key you don't need a query to get the entity, you can simply get it by key lookup:

    V = key.get()