[英]google app engine Efficient way to put large data in datastore
我想将数据存储在父子层次结构中。 我想使用ndb.put_multi函数这样做。 问题是在使用put multi存储父模型后,如何获得父母的相应键。 请提出解决方案
如果您已经将put_multi用于父键,那么您已经拥有了它们。
例如
list_of_parent_keys = ndb.put_multi(list_of_entities)
child_keys = []
for parent_key in list_of_parent_keys:
child_key = ndb.Key(Parent, parent_key, Child, child_key)
child_keys.append(child_key)
诀窍是存储“祖父母”或根实体,并让所有父实体在其密钥中引用它:
root = BaseClass()
root.put()
parent = Parent(parent=root)
parent.put()
child = Child(parent=parent)
child.put()
现在,您可以使用Instance方法检查子项的键:
parent = child.key.parent()
ancestors = child.key.pairs()
您想要根实体的原因是Ancestor查询 :
parents = Parent.query(ancestor=root)
children = Child.query(ancestor=root)
然后,您可以检查child.key.parent()
以查看其父键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.