以下是我的模型:
$ b在运行查询的过程中发现了这个特殊问题,确认该记录存在,并返回零计数。 $ b class描述(ndb.Model): description = ndb.TextProperty() time_posted = ndb.DateTimeProperty(auto_now_add = True ) uuid = ndb.StringProperty() $ b $ class Examine(ndb.Model): updated = ndb.DateTimeProperty(auto_now = True,auto_now_add = True)描述= ndb.StructuredProperty(Description,repeated = True) active = ndb.KeyProperty(kind =描述) slug = ndb.StringProperty(indexed = True) d_id ='ef531b70-3486-11e3-9500-ef31d661e6b2' cnt = Description.query(Description.uuid == d_id).count()我将以cnt结果为0。有人可以向我解释为什么会发生这种情况吗?
解决方案Datastore查询最终一致。这意味着如果底层数据发生变化,有时一个查询将无法反映这种变化。
为了解决这个问题,您可以将您的数据存储和查询构建为强一致: developers.google/appengine/docs/python/datastore/structuring_for_strong_consistency
如果描述实体被保存在检查的父键中,那么下面的查询将是非常一致的:
cnt = Description.query( ancestor = ExamineKey).filter(Description.uuid == d_id).count()
I found this peculiar problem where running a Query, confirming the record exists, returns a count of zero.
Here are my models:
class Description(ndb.Model): description = ndb.TextProperty() time_posted = ndb.DateTimeProperty(auto_now_add=True) uuid = ndb.StringProperty() class Examine(ndb.Model): updated = ndb.DateTimeProperty(auto_now=True, auto_now_add=True) descriptions = ndb.StructuredProperty(Description, repeated=True) active = ndb.KeyProperty(kind=Description) slug = ndb.StringProperty(indexed=True)Assume that I'm running the following, confirming that the specific UUID does exist in the datastore:
d_id = 'ef531b70-3486-11e3-9500-ef31d661e6b2' cnt = Description.query(Description.uuid == d_id).count()I will receive 0 as a result for cnt. Could somebody explain to me why this is happening?
解决方案Datastore queries are eventually consistent. Meaning that if the underlying data changes, sometimes a query will fail to reflect this change.
To remedy this you can structure your datastore and queries to be strongly consistent: developers.google/appengine/docs/python/datastore/structuring_for_strong_consistency
If the description entity was saved within a parent key of examine then the following query would be strongly consistent:
cnt = Description.query(ancestor=ExamineKey).filter(Description.uuid == d_id).count()
更多推荐
NDB查询返回零结果。数据存储显示结果
发布评论