检查实体中是否存在某个字段
我已经更新了数据存储中的模型,因此现在它有一个附加字段。现在我有带有和没有该字段的实体,但我需要将此字段添加到所有尚不具有该字段的实体。想法是在没有该字段的函数中获取实体并添加它。那么,我想知道如何过滤数据存储请求中的此类实体?
I have updated my model in Datastore so now it has an additional field. Now I have entities with and without that field but I need to add this field to all entities that don't yet have it. Idea is to get entities in a function without that field and add it. So, I wonder how I can filter such entities in Datastore requests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法过滤不存在的属性。每个查询都必须由索引来满足,并且不存在缺少给定属性的实体的“负索引”。
通常,您需要迭代所有实体,并忽略已经具有该属性的实体。
You cannot filter for property non-existence. Every query must be satisfied by an index, and there's no "negative index" of entities that lack a given property.
Generally, you'll need to iterate over all entities, and just ignore the ones that already have the property.
这可能没那么容易,但我想这是可能的。
您无法获取没有属性的实体:
您可以获得该特定属性的所有过滤:
我的建议是从所有实体中获取键,并从具有该属性的实体中减去带有键的列表。
参考:
http://code.google。 com/intl/en-US/appengine/docs/python/datastore/queries.html#概述
It might not be so easy, but I guess it's possible.
You cannot get the entities without a property:
You could get all filtering on that specific property:
My suggestion is to get the keys from all and subtract the list with keys from entities with that property.
Reference:
http://code.google.com/intl/en-US/appengine/docs/python/datastore/queries.html#Overview