简体   繁体   English

AppEngine:查询数据存储以获取记录<missing>价值</missing>

[英]AppEngine: Query datastore for records with <missing> value

I created a new property for my db model in the Google App Engine Datastore.我在 Google App Engine 数据存储中为我的数据库模型创建了一个新属性。

Old:老的:

class Logo(db.Model):
  name = db.StringProperty()
  image = db.BlobProperty()

New:新的:

class Logo(db.Model):
  name = db.StringProperty()
  image = db.BlobProperty()
  is_approved = db.BooleanProperty(default=False)

How to query for the Logo records, which to not have the 'is_approved' value set?如何查询 Logo 记录,其中没有设置 'is_approved' 值? I tried我试过

logos.filter("is_approved = ", None)

but it didn't work.但它没有用。 In the Data Viewer the new field values are displayed as.在数据查看器中,新字段值显示为。

According to the App Engine documentation on Queries and Indexes , there is a distinction between entities that have no value for a property, and those that have a null value for it;根据关于Queries and Indexes的 App Engine 文档,没有属性值的实体和具有null值的实体之间存在区别; and "Entities Without a Filtered Property Are Never Returned by a Query."和“没有过滤属性的实体永远不会被查询返回。” So it is not possible to write a query for these old records.所以不可能为这些旧记录编写查询。

A useful article is Updating Your Model's Schema , which says that the only currently-supported way to find entities missing some property is to examine all of them.一篇有用的文章是Updating Your Model's Schema ,它说当前唯一支持的查找缺少某些属性的实体的方法是检查所有实体。 The article has example code showing how to cycle through a large set of entities and update them.文章中的示例代码展示了如何循环访问大量实体并更新它们。

A practice which helps us is to assign a "version" field on every Kind.一种对我们有帮助的做法是为每个 Kind 分配一个“版本”字段。 This version is set on every record initially to 1. If a need like this comes up (to populate a new or existing field in a large dataset), the version field allows iteration through all the records containing "version = 1".此版本在每条记录上最初设置为 1。如果出现这样的需要(在大型数据集中填充新字段或现有字段),版本字段允许迭代所有包含“version = 1”的记录。 By iterating through, setting either a "null" or another initial value to the new field, bump the version to 2, store the record, allows populating the new or existing field with a default value.通过迭代,为新字段设置“null”或另一个初始值,将版本提高到 2,存储记录,允许使用默认值填充新字段或现有字段。

The benefit to the "version" field is that the selection process can continue to select against that lower version number (initially set to 1) over as many sessions or as much time is needed until ALL records are updated with the new field default value. “版本”字段的好处是选择过程可以在尽可能多的会话或需要尽可能多的时间之前继续选择较低版本号(最初设置为 1),直到所有记录都更新为新的字段默认值。

Maybe this has changed, but I am able to filter records based on null fields.也许这已经改变,但我能够根据字段过滤记录。

When I try the GQL query SELECT * FROM Contact WHERE demo=NULL , it returns only records for which the demo field is missing.当我尝试 GQL 查询SELECT * FROM Contact WHERE demo=NULL时,它仅返回缺少演示字段的记录。

According to the doc http://code.google.com/appengine/docs/python/datastore/gqlreference.html :根据文档http://code.google.com/appengine/docs/python/datastore/gqlreference.html

The right-hand side of a comparison can be one of the following (as appropriate for the property's data type): [...] a Boolean literal, as TRUE or FALSE;比较的右侧可以是以下之一(适用于属性的数据类型):[...] 布尔文字,如 TRUE 或 FALSE; the NULL literal, which represents the null value (None in Python). NULL文字,表示空值(Python 中为 None)。

I'm not sure that "null" is the same as "missing" though: in my case, these fields already existed in my model but were not populated on creation.不过,我不确定“null”是否与“缺失”相同:就我而言,这些字段已经存在于我的模型中,但在创建时并未填充。 Maybe Federico you could let us know if the NULL query works in your specific case?也许 Federico 您可以让我们知道 NULL 查询是否适用于您的特定情况?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 避免在 AppEngine 数据存储中的过滤器中 - Avoiding in Filter in AppEngine Datastore 使用 Ant 编译具有数据存储回调的 AppEngine 项目 - Compile AppEngine project that has datastore callbacks with Ant 谷歌云数据存储查询 - Google Cloud Datastore Query's 数据存储模式下的 gcp firestore 是否支持 OR 查询? - Does gcp firestore in datastore mode support OR query? 数据存储区查询结果列表的“实体”部分是什么? - What is the "Entity" part of the Datastore query results list? 查询数据存储以获取存在的属性值集 - Query datastore for the set of property values present 使用 gcp 数据存储中的“IN”查询多个文档中的值 - Query values in multiple document using "IN" in gcp datastore 由于缺少 api 代理,从 Google Appengine 发送电子邮件失败 - Sending emails from Google Appengine fails because of missing api proxy 使用 dev_appserver.py 和 google.golang.org/appengine@v1.6.6 连接到谷歌云数据存储 - Connect to Google Cloud Datastore using dev_appserver.py & google.golang.org/appengine@v1.6.6 Google App Engine:java.lang.ClassCastException:com.google.appengine.api.datastore.Key 无法转换为 java.lang.Integer - Google App Engine: java.lang.ClassCastException: com.google.appengine.api.datastore.Key cannot be cast to java.lang.Integer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM