数据存储区模式下的新Google Cloud Firestore查询澄清 [英] New Google Cloud Firestore in Datastore mode Queries Clarification

查看:69
本文介绍了数据存储区模式下的新Google Cloud Firestore查询澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用新的Google Firestore数据存储区模式(我已经使用旧版本的数据存储区)来掌握查询在交易中的实际工作方式时,我遇到了困难.

I'm having a difficult time grasping how queries really work on transactions with the new Google Firestore Datastore mode( I already worked with the previous version of Datastore).

根据文档,这些是使用数据存储区模式下的Google Cloud Direbase:

According to the documentation these are the benefits of using the Google Cloud Direbase in Datastore mode:

  • 最终的一致性,所有Cloud Datastore查询都将变得非常一致.
  • 交易不再局限于25个实体组.
  • 对实体组的写入不再限于每秒1个.
  • Eventual consistency, all Cloud Datastore queries become strongly consistent.
  • Transactions are no longer limited to 25 entity groups.
  • Writes to an entity group are no longer limited to 1 per second.

由于查询现在已经非常一致,因此我认为可以在事务内使用非祖先查询,但是可以在文档另有说明:

Since the queries are now strongly consistent, I assumed that it would be okay to use non-ancestor queries inside a transaction, but in the documentation says otherwise:

交易内部的查询必须是祖先查询

Queries inside transactions must be ancestor queries

深思熟虑之后,我决定尝试看看我的怀疑是否正确:

After thinking deeply about it, I decided to try to see if my suspicions were correct:

query := datastore.NewQuery("Entity").Filter("indexed_property =", s)
ctx := context.Background()
tx, err := client.NewTransaction(ctx, datastore.ReadOnly)
if err != nil {
  fmt.Pritnln(err)
}
query = query.Transaction(tx)
it := d.client.Run(ctx, query)
e := new(Entity)
_, err = it.Next(e)
if err != nil || err == iterator.Done {
  fmt.Println(err)
}

令我惊讶的是,它完美地工作了.这是错误还是正确的行为?

For my surprise, It worked flawlessly. So this is a bug or the correct behavior?

推荐答案

您是正确的.这是文档中的错误.数据存储模式下的Cloud Firestore消除了限制,即交易内部的查询必须是祖先查询.

You are correct. This was a bug in the documentation. Cloud Firestore in Datastore mode removes the restriction that queries inside transactions must be ancestor queries.

页面现已更新.对此感到抱歉.

The page is now updated. Apologies for the confusion.

这篇关于数据存储区模式下的新Google Cloud Firestore查询澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆