检查实体中是否存在某个字段

发布于 2024-11-29 00:10:02 字数 121 浏览 1 评论 0原文

我已经更新了数据存储中的模型,因此现在它有一个附加字段。现在我有带有和没有该字段的实体,但我需要将此字段添加到所有尚不具有该字段的实体。想法是在没有该字段的函数中获取实体并添加它。那么,我想知道如何过滤数据存储请求中的此类实体?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不…忘初心 2024-12-06 00:10:02

您无法过滤不存在​​的属性。每个查询都必须由索引来满足,并且不存在缺少给定属性的实体的“负索引”。

通常,您需要迭代所有实体,并忽略已经具有该属性的实体。

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.

硪扪都還晓 2024-12-06 00:10:02

这可能没那么容易,但我想这是可能的。

您无法获取没有属性的实体:

不使用匹配缺少属性的实体的过滤器

无法查询缺少给定属性的实体。一种替代方法是创建默认值 None 的固定(建模)属性,然后为属性值 None 的实体创建过滤器。

您可以获得该特定属性的所有过滤:

对属性进行过滤或排序需要该属性存在

如果属性具有查询过滤条件或排序顺序,则查询仅返回具有该属性值(包括 null)的数据存储区实体。
同类实体不必具有相同的属性。属性上的过滤器只能匹配具有该属性值的实体。如果某个实体在过滤器或排序顺序中使用的属性没有值,则该实体将从为查询构建的索引中省略。

我的建议是从所有实体中获取键,并从具有该属性的实体中减去带有键的列表。

参考:
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:

No Use of Filters That Match Entities Missing a Property

It is not possible to query for entities that are missing a given property. One alternative is to create a fixed (modeled) property with a default value of None, then create a filter for entities with None as the property value.

You could get all filtering on that specific property:

Filtering Or Sorting On a Property Requires That the Property Exists

If a property has a query filter condition or sort order, the query returns only those datastore entities that have a value (including null) for that property.
Entities of a kind need not have the same properties. A filter on a property can only match an entity with a value for that property. If an entity has no value for a property used in a filter or sort order, that entity is omitted from the index built for the query.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文