I have a data structure like:
I want to edit the value of "test" key in "first" object. I followed the document on https://firebase.google.com/docs/firestore/manage-data/add-data
But it did not work for me.
The nodejs code:
var setAda = dbFirestore.collection('users').doc('alovelace').update({
first : {
test: "12345"
}
});
The "test2" key was gone. However, I only want to update the value of "test" and keep the "test2".
Any solution for this problem?
Try this one: Does it work like that?
For those who need something more generic and recursive, here is a function that updates a Foo Firestore document non destructively with a typescript Partial :
In case somebody is using TypeScript (like in Cloud functions for example) here is the code to update nested fields with dot notation.
Peter's solution's great, but it's not works with dynamic key. This code is far better:
According to the link you provided, it says this:
Therefore you need to use
dot notation
to be able to update only one field without overwriting, so like this:then you will have: