progNewbie
progNewbie

Reputation: 4812

Use a field value to update another field in same document

I am using Firebase Firestore and have documents with two fields:

field X
field Y

They are both numbers. Now I want to copy the value from X to Y. Of course I can just read the document to have the value X and then do a write operation on the same document and update field Y.

My question is, if there is a possibility to do this with just an update-operation as I couldn't find anything related but it seems to me like this might be something that's implemented by Firebase.

Thank you

Upvotes: 2

Views: 606

Answers (2)

an92kz
an92kz

Reputation: 123

Depending on your needs, you can use transactions. For instance, I used it for the rating functionality, and actually, you might find this thread helpful.

Upvotes: 0

Kevin Kreps
Kevin Kreps

Reputation: 758

Unfortunately, something like you described is not possible. One would simply read the document and update it with the read value.

Upvotes: 2

Related Questions