5

So, I know there are a few similarly named questions, but this is not the same. I am curious to see if anyone could explain the reasoning for the lack of an increment sentinel, similar to the delete one.

As far as I know, a field deletion is no different than a document update. Meaning, I can just delete my field by simply updating the entire document to some new data, leaving that field out, hence, the question.

If we have a FieldValue.delete(), why the lack of a FieldValue.increment()

Note: I am aware of the 1QPS limit and I doubt it has anything to do with the above.

Regards!

1 Answer 1

5

Version 5.9.0 - Mar 14, 2019

Added FieldValue.increment(), which can be used in update() and set(..., {merge:true}) to increment or decrement numeric field values safely without transactions.

https://firebase.google.com/support/release-notes/js

Sign up to request clarification or add additional context in comments.

5 Comments

Perfect :) Thank you so much!
Is this currently working in cloud functions? When I try to use it the value is never incremented.
@ajaxon You can access that in functions from the firestore static property admin.firestore.FieldValue.increment(1)
@HamishJohnson this doesn't seem to work for nested object properties. is it supposed to?
@Crashalot I haven't tested but yes it should

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.