Reputation: 1148
As the cloud firestore in datastore mode supports strong consistency for all queries,
https://cloud.google.com/datastore/docs/firestore-or-datastore#in_datastore_mode
could this be used to check for uniqueness? Say I have a user entity (top level entity) that has a datastore allocated ID as the key. In the past, it wasn't possible to do a query by email within the transaction as it was a global query. But it seems that it is now possible to do such queries as clarified at
New Google Cloud Firestore in Datastore mode Queries Clarification
Does this mean it is now possible to ensure there are no duplicate User entities by just indexing and querying by the email property within the transaction to insert the User entity?
My current implementation is to have a separate entity that has a named key using the email and do a key based query on that entity within the transaction. I can get rid of that if I can query by email on the User entity itself within the transaction and it guarantees duplicate entities won't be created under race condition.
Upvotes: 0
Views: 265
Reputation: 1148
After some research, below is all I could gather.
Upvotes: 1
Reputation: 171
As of right now, there is no way to enforce uniqueness on a property. However, there are workarounds for what you are trying to do. One workaround is explained in the article linked above, and another is here.
Upvotes: 0