简体   繁体   中英

NDB: Query for unset properties?

I've had some data being gathered in production for a couple of days with, lets say, the following model:

class Tags(ndb.Model):
    dt_added = ndb.DateTimeProperty(auto_now_add=True)
    s_name   = ndb.StringProperty(required=True, indexed=True)

Imagine I now add a new property to the model:

class Foo(ndb.Model):
    is_valid = ndb.BooleanProperty(default=False)
    some_key = ndb.KeyProperty(repeated=True)

class Tags(ndb.Model):
    dt_added = ndb.DateTimeProperty(auto_now_add=True)
    name     = ndb.StringProperty(required=True, indexed=True)
    new_prop = ndb.StructuredProperty(Foo)

... and gather some more data with this new model.

So now I have a portion of data that has the property new_prop set, and another portion that does not have it set.

My question is: how to I query for the data with the new property new_prop NOT set?

I've tried:

query_tags = Tags.query(Tags.new_prop == None).fetch()

But does not seem to get the data without that property set... Any suggestions? Thanks!

The Datastore distinguishes between an entity that does not possess a property and one that possesses the property with a null value (None).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM