1
votes

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

1 Answers

2
votes

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.