AppEngine: Query datastore for records with <missing> value

不羁的心 提交于 2019-11-27 20:30:54

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; 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. The article has example code showing how to cycle through a large set of entities and update them.

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.

According to the doc 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; the NULL literal, which represents the null value (None in Python).

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. Maybe Federico you could let us know if the NULL query works in your specific case?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!