Google-cloud-dotnet: What if we use UpdateDocumentAsync with empty mask?

Created on 9 Jan 2018  路  9Comments  路  Source: googleapis/google-cloud-dotnet

UpdateDocumentAsync api has required parameters document and updateMask

The document just state that if any fields does not specified in the mask it would not be overridden. Which means if document already exist and we put an empty new DocumentMask() it would not write any changed field existing isn't it?

If it behave like this, what API should we call for override everything?

firestore question

All 9 comments

If you specify an empty document mask, it wouldn't change any fields - or would throw an exception; I can't remember offhand.

If you want to completely overwrite the existing data, use Set instead of Update.

@jskeet I see. Because I have seen no Set api for the low level firestoreClient

So I just look for high level and it seem Set just use ExtractDocumentMask then update

Is it really normal for firestore that we use update with mask of all field to override everything?

I believe so, but I'd have to look at the code in more detail to check. (I'm currently at a conference, just trying to catch up with mail - I'm not working in my normal capacity this week.) Again, for low-level API details it's probably best to ask in a Firestore-specific forum rather than here, as I'm really not an expert in Firestore in general.

cc @schmidt-sebastian

The Firestore clients use create, set and update for the same Protobuf operation. They each use the Protobuf in a slightly different way. set by default overrides the data on the server, and this is achieved by not sending a document mask to the backend.

@schmidt-sebastian Thank you very much. Is that was documented anywhere? Because I have seen only mention that a field which not exist in mask will not get update, but it I have seen nowhere mention that if there is no mask at all it would be full overridden

I suspect this behavior just not sure and not see document about it

@schmidt-sebastian And also I have seen Firestore api was implemented by using ExtractDocumentMask which means it send every field as a mask instead of just no mask?

https://github.com/GoogleCloudPlatform/google-cloud-dotnet/blob/3cc3a1b31bc1cf827deb243d115f8d8456cade13/apis/Google.Cloud.Firestore/Google.Cloud.Firestore/WriteBatch.cs#L143-L157

The code path you've shown is when SetOptions.Merge is set to true.

Otherwise, it uses an empty set of paths:

https://github.com/GoogleCloudPlatform/google-cloud-dotnet/blob/fac8204336424cb797aa120461f883cf9fdd5ac2/apis/Google.Cloud.Firestore/Google.Cloud.Firestore/WriteBatch.cs#L175-L187

I suspect this behavior just not sure and not see document about it

As far as I can tell, this is not yet documented in the Protobuf definition. I created an internal PR to add this caveat.

Thank you very much for all of responses

Was this page helpful?
0 / 5 - 0 ratings

Related issues

riiight picture riiight  路  9Comments

Talento90 picture Talento90  路  6Comments

Eldar-Ahmadov picture Eldar-Ahmadov  路  6Comments

fagnercarvalho picture fagnercarvalho  路  5Comments

haf picture haf  路  6Comments