NDB查询返回零结果。数据存储显示结果

编程入门 行业动态 更新时间:2024-10-21 16:30:34
本文介绍了NDB查询返回零结果。数据存储显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下是我的模型:

$ 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查询返回零结果。数据存储显示结果

本文发布于:2023-10-13 10:17:13,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据存储   NDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!