我有ndb模态,它具有字符串重复属性。我正在尝试检索所有具有空值的实体。但 NDB 查询返回空。
class A(ndb.model):
name = ndb.StringProperty()
values = ndb.StringProperty(repeated=True)
a1 = A()
a1.name = "T1"
a1.values = ['V1', 'V2']
a1.put()
a2 = A()
a2.name = "T2"
a2.values = []
a2.put()
result = A.query(A.values=="") # Return empty
result = A.query(A.values==[]) # BadValueError: Expected string, got []
for each in result:
print each.name
如何查询具有空/无值的实体?
最佳答案
我认为您必须将查询基于另一个保存值数量的字段,例如,
num_values = ndb.IntegerProperty(indexed=True)
每次更新值
字段时,您都必须更新此数字。然后你可以这样查询:
result = A.query(A.num_values==0)
这与另一个问题类似:NDB: Sort query results
关于python - NDB 查询重复 StringProperty 中的空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32593449/