New Google Cloud Firestore in Datastore mode Queries Clarification

天大地大妈咪最大 提交于 2019-12-31 04:44:06

问题


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

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/56506230/new-google-cloud-firestore-in-datastore-mode-queries-clarification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!