数据存储模式下的新 Google Cloud Firestore 查询说明

New Google Cloud Firestore in Datastore mode Queries Clarification

我很难理解查询在使用新的 Google Firestore Datastore 模式(我已经使用过以前版本的 Datastore)的交易中是如何工作的。

根据documentation,这些是在数据存储模式下使用 Google Cloud Direbase 的好处:

  • 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.

由于查询现在是高度一致的,我认为在事务中使用非祖先查询是可以的,但在 documentation 中另有说明:

Queries inside transactions must be ancestor queries

深思熟虑后,我决定试一试,看看我的猜测是否正确:

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)
}

令我惊讶的是,它运行完美。这是错误还是正确的行为?

你是对的。这是文档中的错误。 Datastore 模式下的 Cloud Firestore 取消了事务内查询必须是祖先查询的限制。

页面现已更新。对造成的混乱表示歉意。