简体   繁体   中英

Querying a repeated property by count in NDB

Is there an efficient mechanism for querying by the number of items in a repeated property in NDB?

I'd like to do something like:

Class.query(class.repeated_property.count == 2)

but of course this doesn't work.

Specifically, you can use ComputedProperty to automatically store the count, eg

class X(ndb.Model):
  prop = ndb.StringProperty(repeated=True)
  prop_count = ndb.ComputedProperty(lambda e: len(e.prop))

X.query(X.prop_count == 2)

在GQL中没有len查询语义,您需要具有列表长度的sperate属性并对其进行查询。

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