【发布时间】:2019-06-08 12:09:32
【问题描述】:
在使用新的 Google Firestore Datastore 模式(我已经使用过以前版本的 Datastore)时,我很难理解查询是如何在事务上真正起作用的。
根据documentation,这些是在数据存储模式下使用 Google Cloud Direbase 的好处:
- 最终一致性,所有 Cloud Datastore 查询都变得高度一致。
- 事务不再限于 25 个实体组。
- 对实体组的写入不再限制为每秒 1 次。
由于查询现在是高度一致的,我认为在事务中使用非祖先查询是可以的,但在 documentation 中另有说明:
事务中的查询必须是祖先查询
深思熟虑后,我决定试试看我的怀疑是否正确:
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)
}
令我惊讶的是,它完美无缺。所以这是一个错误还是正确的行为?
【问题讨论】:
标签: google-cloud-firestore google-cloud-datastore